Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SQL
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();
Posted

The update command only has 1 set, remove the extra set statements : http://www.w3schools.com/sql/sql_update.asp[^]
 
Share this answer
 
You only need the SET once, after that just comma separated field/value pairs.
Change your query to this:
C#
UpdateCommand.CommandText = "UPDATE dbo.ComapnyName SET GovermentID=@123, RegistrationNumber=@asd, Address1=@aaaa, Address2=@addres, City=@city, PostalCode=@post Where CompanyName=@text1";
 
Share this answer
 
You did wrong update query, following is the correct way:
SQL
UpdateCommand.CommandText = "UPDATE dbo.ComapnyName SET GovermentID=@123, RegistrationNumber=@asd, Address1=@aaaa, Address2=@addres, City=@city, PostalCode=@post Where CompanyName=@text1";
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900