Update Command有错误。关键字“SET”附近的语法不正确。 [英] Update Command has a error. Incorrect syntax near the keyword 'SET'.
本文介绍了Update Command有错误。关键字“SET”附近的语法不正确。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
UpdateCommand.CommandText = UPDATE dbo.ComapnyName SET GovermentID = @ 123, SET RegistrationNumber = @ asd,SET Address1 = @ aaaa,SET Address2 = @ addres,SET City = @ city,SET PostalCode = @ post Where CompanyName = @ text1;
UpdateCommand.Parameters.AddWithValue( @ text1,Class1.Text1 );
UpdateCommand.Parameters.AddWithValue( @ 123,SqlDbType。 VarChar )。Value = textBox3。 Text .Trim();
UpdateCommand.Parameters.AddWithValue( @ asd,SqlDbType。 VarChar )。Value = textBox4。 Text .Trim();
UpdateCommand.Parameters.AddWithValue( @ aaaa,SqlDbType。 VarChar )。Value = textBox5。 Text .Trim();
UpdateCommand.Parameters.AddWithValue( @ addres,SqlDbType。 VarChar )。Value = textBox6。 Text .Trim();
UpdateCommand.Parameters.AddWithValue( @ city,SqlDbType。 VarChar )。Value = textBox8。 Text .Trim();
UpdateCommand.Parameters.AddWithValue( @ post,SqlDbType。 VarChar )。Value = textBox7。 Text .Trim();
UpdateCommand.CommandType = CommandType。 Text ;
UpdateCommand.Connection = myConnection1;
尝试
{
UpdateCommand.ExecuteNonQuery();
解决方案
< blockquote> update
命令只有 1 set
,删除额外的set语句:< a href =http://www.w3schools.com/sql/sql_update.asp> http://www.w3schools.com/sql/sql_update.asp [ ^ ]
您只需要SET一次,之后只是以逗号分隔的字段/值对。
将您的查询更改为:
UpdateCommand.CommandText = UPDATE dbo.ComapnyName SET GovermentID = @ 123,RegistrationNumber = @ asd,Address1 = @ aaaa,Address2 = @ addres,City = @ city,PostalCode = @ post Where CompanyName = @ text1;
你做错了更新查询,以下是正确的方法:
UpdateCommand.CommandTex t = UPDATE dbo.ComapnyName SET GovermentID = @ 123,RegistrationNumber = @ asd,Address1 = @ aaaa,Address2 = @ addres,City = @ city,PostalCode = @ post Where CompanyName = @ text1;
UpdateCommand.CommandText = "UPDATE dbo.ComapnyName SET GovermentID=@123,SET RegistrationNumber=@asd,SET Address1=@aaaa,SET Address2=@addres,SET City=@city,SET PostalCode=@post Where CompanyName=@text1";
UpdateCommand.Parameters.AddWithValue("@text1", Class1.Text1);
UpdateCommand.Parameters.AddWithValue("@123", SqlDbType.VarChar).Value = textBox3.Text.Trim();
UpdateCommand.Parameters.AddWithValue("@asd", SqlDbType.VarChar).Value = textBox4.Text.Trim();
UpdateCommand.Parameters.AddWithValue("@aaaa", SqlDbType.VarChar).Value = textBox5.Text.Trim();
UpdateCommand.Parameters.AddWithValue("@addres", SqlDbType.VarChar).Value = textBox6.Text.Trim();
UpdateCommand.Parameters.AddWithValue("@city", SqlDbType.VarChar).Value = textBox8.Text.Trim();
UpdateCommand.Parameters.AddWithValue("@post", SqlDbType.VarChar).Value = textBox7.Text.Trim();
UpdateCommand.CommandType = CommandType.Text;
UpdateCommand.Connection = myConnection1;
try
{
UpdateCommand.ExecuteNonQuery();
解决方案
Theupdate
command only has 1set
, remove the extra set statements : http://www.w3schools.com/sql/sql_update.asp[^]
You only need the SET once, after that just comma separated field/value pairs.
Change your query to this:
UpdateCommand.CommandText = "UPDATE dbo.ComapnyName SET GovermentID=@123, RegistrationNumber=@asd, Address1=@aaaa, Address2=@addres, City=@city, PostalCode=@post Where CompanyName=@text1";
You did wrong update query, following is the correct way:
UpdateCommand.CommandText = "UPDATE dbo.ComapnyName SET GovermentID=@123, RegistrationNumber=@asd, Address1=@aaaa, Address2=@addres, City=@city, PostalCode=@post Where CompanyName=@text1";
这篇关于Update Command有错误。关键字“SET”附近的语法不正确。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文