我在 vb.net 中尝试更新语句。我的代码在下面
'Connection statement
Dim con As New MySqlConnection("server =nnnnnnnnn; user =nnnnnnnnn; password= nnnnnnnnnnnnnn; database =nnnnn;")
'SQL query
Dim cmdText = "UPDATE contacts SET (title_name = @cotitle, contact_name = @coname, contact_mname = @comname, contact_pref_fname = @coprefname, contact_jobtitle = @cojobtitle, contact_job_sector = @cojobsector, contact_company = @coemp, contact_preflang = @colang, contact_home_nation = @cohomenat, contact_srequirements = @cosreqs, contact_street = @costreet, contact_town = @cotown, contact_postcode = @copcode, contact_resident_country = @cocountry, contact_email = @coemail, contact_phone = @cophone, contact_mobile = @comob, contact_notes = @conotes, contact_influence_level = @coinf, contact_optout_email = @cooptemail, contact_optout_phone = @cooptphone, contact_optout_post = @cooptpost WHERE contact_id = @coid);"
'commit SQL query with connection statement
Dim com As New MySqlCommand(cmdText, con)
'place fields into parameters for the query
com.Parameters.AddWithValue("@coid", contact_id.Text)
com.Parameters.AddWithValue("@cotitle", ComboBox1.Text)
com.Parameters.AddWithValue("@coname", TextBox3.Text)
com.Parameters.AddWithValue("@comname", TextBox4.Text)
com.Parameters.AddWithValue("@coprefname", TextBox1.Text)
com.Parameters.AddWithValue("@cojobtitle", TextBox2.Text)
com.Parameters.AddWithValue("@cojobsector", ComboBox7.Text)
com.Parameters.AddWithValue("@coemp", ComboBox8.Text)
com.Parameters.AddWithValue("@colang", ComboBox3.Text)
com.Parameters.AddWithValue("@cohomenat", ComboBox4.Text)
com.Parameters.AddWithValue("@cosreqs", RichTextBox2.Text)
com.Parameters.AddWithValue("@costreet", RichTextBox1.Text)
com.Parameters.AddWithValue("@cotown", TextBox8.Text)
com.Parameters.AddWithValue("@copcode", TextBox9.Text)
com.Parameters.AddWithValue("@cocountry", ComboBox5.Text)
com.Parameters.AddWithValue("@coemail", TextBox6.Text)
com.Parameters.AddWithValue("@cophone", TextBox10.Text)
com.Parameters.AddWithValue("@comob", TextBox12.Text)
com.Parameters.AddWithValue("@conotes", RichTextBox4.Text)
com.Parameters.AddWithValue("@coinf", ComboBox6.Text)
com.Parameters.AddWithValue("@cooptemail", CheckBox1.Checked)
com.Parameters.AddWithValue("@cooptphone", CheckBox2.Checked)
com.Parameters.AddWithValue("@cooptpost", CheckBox3.Checked)
'this will commit the record to the DB
con.Open()
com.ExecuteNonQuery()
con.Close()
它说 SQL 语法错误,但我无法发现它。任何帮助表示赞赏。