Inserting data into a MySQL table using VB.NET

前端 未结 6 2046
别跟我提以往
别跟我提以往 2020-12-10 20:46

I have a problem inserting data into a table on a MySQL database using a VB.NET application. I have a simple form where when I set some data to the textboxes and I press a

6条回答
  •  鱼传尺愫
    2020-12-10 21:21

    You need to use ?param instead of @param when performing queries to MySQL

     str_carSql = "insert into members_car (car_id, member_id, model, color, chassis_id, plate_number, code) values (?id,?m_id,?model,?color,?ch_id,?pt_num,?code)"
            sqlCommand.Connection = SQLConnection
            sqlCommand.CommandText = str_carSql
            sqlCommand.Parameters.AddWithValue("?id", TextBox20.Text)
            sqlCommand.Parameters.AddWithValue("?m_id", TextBox20.Text)
            sqlCommand.Parameters.AddWithValue("?model", TextBox23.Text)
            sqlCommand.Parameters.AddWithValue("?color", TextBox24.Text)
            sqlCommand.Parameters.AddWithValue("?ch_id", TextBox22.Text)
            sqlCommand.Parameters.AddWithValue("?pt_num", TextBox21.Text)
            sqlCommand.Parameters.AddWithValue("?code", ComboBox1.SelectedItem)
            sqlCommand.ExecuteNonQuery()
    

    Change the catch block to see the actual exception:

      Catch ex As Exception
             MsgBox(ex.Message)   
              Return False
    
        End Try
    

提交回复
热议问题