简体   繁体   English

sql语法中出现错误,vb.net中的mysql更新语句

[英]getting an error in sql syntax, mysql update statement in vb.net

Im trying an update statement in vb.net. 我正在尝试在vb.net中进行更新。 my code is below 我的代码如下

'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()

it says error in SQL syntax, but i cant spot it. 它说SQL语法中的错误,但我无法发现它。 any help appreciated. 任何帮助表示赞赏。

remove the parenthesis on the statement 删除语句上的括号

UPDATE contacts 
SET title_name = @cotitle, contact_name = @coname,....

your update query should be like this 您的更新查询应该是这样的

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

Need to remove the ( and ) 需要删除()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM