Click here to Skip to main content
12,070,942 members (66,030 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# 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 4:40am
mrDivan1.1K
Edited 8-Oct-12 4: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 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
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web04 | 2.8.160208.1 | Last Updated 8 Oct 2012
Copyright © CodeProject, 1999-2016
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