Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET MySQL C#4.0
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
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;
 
sqlcom.Connection = mycon1;
               sqlcom.ExecuteNonQuery();
               mycon1.Close();
Posted 8-Oct-12 3:40am
mrDivan891
Edited 8-Oct-12 3:44am
v2

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Change this:
 
MySqlCommand sqlcom = new MySqlCommand("UPDATE t_company SET Company_Name=@Company_Name,Description=@Description,Email=@Email where Company_Name=@Company_Name'" + "'", mycon1);
 
to this:
 
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:
 
sqlcom.Connection = mycon1;
 
as you have already specified it in your MySqlCommand constructor.
  Permalink  
Comments
mrDivan at 8-Oct-12 10:29am
   
Thanks for the advice but it still does not update the values in my database
gladiatron at 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)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 480
1 Gihan Liyanage 225
2 OriginalGriff 174
3 Bhavik_Patel 170
4 PhilLenoir 155
0 Sergey Alexandrovich Kryukov 8,688
1 OriginalGriff 7,237
2 CPallini 2,598
3 Richard MacCutchan 2,080
4 Abhinav S 1,888


Advertise | Privacy | Mobile
Web02 | 2.8.140827.1 | Last Updated 8 Oct 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100