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?
Posted Jul 15, 2014, 5:57 AM
Thanks a lot.
Appasaheb TawalePosted Jul 15, 2014, 5:19 AM
Guest UserPosted Jul 10, 2014, 3:51 AM
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