Avatar of babubhai
babubhai
 asked on

In C#: How can I save changes in Database using SQL Command

Hello Experts,
Im trying to update record in C# but Im getting an error: Incorrect syntax near ','
while I dont have any ',' sign in my form input.
Also update query if fine and working in database.

Could you help me please....thanks in advance

my codes are in Update Button which are below:

string strCon = @"Data Source=YOUR-E659457A65\SQLEXPRESS;Initial Catalog=DLCallLog;Integrated Security=True";
           
            SqlConnection myConnection = new SqlConnection(strCon);
            myConnection.Open();
            string strSQL = "Update [CLIENT TABLE] Set [CLIENT NAME] = '" + ClientName + "' Where JobID = " + JobID;
            SqlCommand cmd = new SqlCommand(strSQL, myConnection);

            cmd.ExecuteReader();
           
            myConnection.Close();
            myConnection.Dispose();
            MessageBox.Show("Record Update successfully");
            this.Close();
.NET Programming

Avatar of undefined
Last Comment
EmrahZengin

8/22/2022 - Mon
Gautham Janardhan

try
cmd.ExecuteScalar();
instead of cmd.ExecuteReader();

 
P_Ramprathap

You need to use cmd.ExecuteNonQuery();
ASKER CERTIFIED SOLUTION
EmrahZengin

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy