Click here to Skip to main content
Sign Up to vote bad
good
See more: ASP.NETMySQLC#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
mrDivan734
Edited 8-Oct-12 3:44am
Aman.A6.5K


1 solution

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 - 8-Oct-12 10:29am
Thanks for the advice but it still does not update the values in my database
gladiatron - 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
Your Filters
Interested
Ignored
     
0 Christian Graus 514
1 Ron Beyer 286
2 OriginalGriff 248
3 samadhan_kshirsagar 229
4 Tadit Dash 213
0 Sergey Alexandrovich Kryukov 7,017
1 Prasad_Kulkarni 3,815
2 OriginalGriff 3,557
3 _Amy 3,372
4 CPallini 3,010


Advertise | Privacy | Mobile
Web03 | 2.6.130619.1 | Last Updated 8 Oct 2012
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid