Below code is for update the record in excel sheet:-
try
{
System.Data.OleDb.OleDbConnection MyConnection;
System.Data.OleDb.OleDbCommand myCommand = new System.Data.OleDb.OleDbCommand();
string sql = null;
MyConnection = new System.Data.OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=d:\\csharp.net-informations.xlsx;Extended Properties=Excel 12.0 Xml;");
MyConnection.Open();
myCommand.Connection = MyConnection;
sql = (@"Update [Sheet1$] set (candidatefname='" + txtFName.Text + "', candidatemname='" + txtMName.Text + "', candidatelname='" + txtLName.Text + "', dob='" + dtpDOB.Value + "', sex='" + cmbSex.Text + "', currentaddress='" + txtCurrentAddress.Text + "', permanentaddress='" + txtParmanentAddress.Text + "', mobilenumber='" + txtMobile.Text + "', mailid='" + txtMailID.Text + "', maritalstatus='" + cmbMaritalStatus.Text + "', experience='" + txtExperience.Text + "', departmentname='" + cmbDepartment.Text + "') where SrNo='" + cID + "' ");
myCommand.CommandText = sql;
myCommand.ExecuteNonQuery();
MyConnection.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
I am getting the error : Syntax error in UPDATE statement.
When I am debugging the code getting all the value perfectly as I want, but in sql object I am getting null value.
So please can anybody tell me what is wrong with this?

Guest UserRank #259 · 9.8K reputationPosted Jul 9, 2014, 11:51 PM EDT
And I suggest you to adopt new ways to update data, e.g., the current code is prone to if there is single quote present in any text box it'll then update will break.
Ideally, you should use any framework, e.g., Entity framework, massive, petapoco to handle these rather handling it traditional way
twitter @sumitjolly
Appasaheb Tawale3 reputationPosted Jul 15, 2014, 1:19 AM EDT
Posted Jul 15, 2014, 1:57 AM EDT
Thanks a lot.