在sql语法中获取错误,在vb.net中获取mysql update语句

时间:2013-02-12 12:37:12

标签: mysql vb.net

我在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语法错误,但我无法发现它。任何帮助表示感谢。

2 个答案:

答案 0 :(得分:0)

删除声明

上的括号
UPDATE contacts 
SET title_name = @cotitle, contact_name = @coname,....

答案 1 :(得分:0)

您的更新查询应该是这样的

UPDATE contacts SET title_name = @cotitle, .....;"

需要删除()