Click here to Skip to main content
15,882,152 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
please help me i want to know what is wrong with my command it doesnot update my database whe i click the update button
this is inside a buttonclick event
first i open an connection did not put the code here because that works
C#
MySqlCommand sqlcom = new MySqlCommand("UPDATE t_company SET Company_Name=@Company_Name,Description=@Description,Email=@Email where Company_Name=@Company_Name'" + "'", mycon1);
sqlcom.Parameters.Add("@Company_Name", MySqlDbType.VarChar, 100).Value = txtCompany_Name.Text;
               sqlcom.Parameters.Add("@Description", MySqlDbType.VarChar, 100).Value = txtDescriptionNumber.Text;
               sqlcom.Parameters.Add("@Email", MySqlDbType.VarChar, 100).Value = txtEmailText;


C#
sqlcom.Connection = mycon1;
               sqlcom.ExecuteNonQuery();
               mycon1.Close();
Posted
Updated 8-Oct-12 3:44am
v2

1 solution

Change this:

C#
MySqlCommand sqlcom = new MySqlCommand("UPDATE t_company SET Company_Name=@Company_Name,Description=@Description,Email=@Email where Company_Name=@Company_Name'" + "'", mycon1);


to this:

C#
MySqlCommand sqlcom = new MySqlCommand("UPDATE t_company SET Company_Name=@Company_Name,Description=@Description,Email=@Email where Company_Name=@Company_Name", mycon1);


i.e. remove the extra quotes that you were appending. Parameterisation in ADO.NET takes care of putting the right quotes for you automatically.

also get rid of:

C#
sqlcom.Connection = mycon1;


as you have already specified it in your MySqlCommand constructor.
 
Share this answer
 
Comments
mrDivan 8-Oct-12 10:29am    
Thanks for the advice but it still does not update the values in my database
I.explore.code 8-Oct-12 10:31am    
are u getting any errors or exceptions?

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