Link to home
Start Free TrialLog in
Avatar of babubhai
babubhai

asked on

Urgent: Update Record in C#

Hello Expers,
Im trying to update a record in C# but Im getting error: Incorrect syntax near ','

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();
Avatar of Jaime Olivares
Jaime Olivares
Flag of Peru image

maybe your ClientName includes some invalid character like a quote or other, could you post the contents of strSQL?
If, as jamie suggests, there are invalid characters in the name or JobID, you can get around the problem by passing the values as parameters. This has the added value of creating a pre-parsed statement in the DB server, so if you need to do it more than once, it will run faster.

Jim
Avatar of babubhai
babubhai

ASKER

is there another solution could you tell me please?
Also I dont have any ( , ) in my data or in any input.... but i dont know why its giving me an error.....
while its working fine in MSSQL database.....

help me please
so, what is the content of strSQL ?
erm...isnt your string incorrect?
.ToString()?
ASKER CERTIFIED SOLUTION
Avatar of EmrahZengin
EmrahZengin
Flag of Türkiye image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial