Updaing excel file using oleDb in c#
-
Am trying to update one cell in excel file using oleDb in c# but I get the following error "Concurrency violation: the UpdateCommand affected 0 records" Many thanks for ur help Excel File Test.xls structure (cell format for both these columns are Text in excel) Col1 Col2 1 100 code snippet using System.Data.OleDb; string ExcelConStr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Test.xls;Extended Properties=Excel 8.0;"; OleDbConnection oleDbConn = new OleDbConnection(ExcelConStr); oleDbConn.Open(); OleDbDataAdapter da = new OleDbDataAdapter("Select * from [Sheet1$]",oleDbConn) DataSet ds = new DataSet(); da.Fill(ds); da.UpdateCommand = new OleDbCommand("Update [Sheet1$] SET Col2= ? Where Col1= ?",oleDbConn); da.UpdateCommand.Parameters.Add("Col1",OleDbType.VarChar,255,"Col1"); da.UpdateCommand.Parameters.Add("Col2",OleDbType.VarChar,255,"Col2"); ds.Tables[0].Rows[0]["Col2"]=500; da.update(ds); Share knowledge to enhance your learning