在 sql 语法中出现错误,vb.net 中的 mysql update 语句
Posted
技术标签:
【中文标题】在 sql 语法中出现错误,vb.net 中的 mysql update 语句【英文标题】:getting an error in sql syntax, mysql update statement in vb.net 【发布时间】:2013-02-12 12:37:12 【问题描述】:我正在 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 语法中显示错误,但我无法发现它。任何帮助表示赞赏。
【问题讨论】:
【参考方案1】:你的更新查询应该是这样的
UPDATE contacts SET title_name = @cotitle, .....;"
需要去掉(
和)
【讨论】:
【参考方案2】:删除语句中的括号
UPDATE contacts
SET title_name = @cotitle, contact_name = @coname,....
【讨论】:
以上是关于在 sql 语法中出现错误,vb.net 中的 mysql update 语句的主要内容,如果未能解决你的问题,请参考以下文章
我的 VB.Net 代码中出现 PL SQL 错误,但无法在 SQL Developer 中重现