Hello everyone,
I'm trying to update an excel file. I used OLEDB connection for read data from excel and now i want to use it for update the data.
I can import data from excel to datagridview. So if there is anyway to update all data from datagridview to excel, it would be great. I'm open for any suggestion.
Here is my code :
OleDbConnection baglan = new OleDbConnection();
baglan.ConnectionString = @"Provider = Microsoft.ACE.OLEDB.12.0; Data Source = " + yeniDosya + "; Extended Properties = 'Excel 8.0;IMEX=1;'";
baglan.Open();
string sit = sheetadi;
sit = sit.TrimEnd('\'');
sit = sit.TrimStart('\'');
string shtsrg = sit + "K" + i + ":K" + i;
string excel = String.Format("UPDATE {0} SET F1=" + dataGridView1.Rows[i].Cells[9].Value.ToString() + "", shtsrg);
MessageBox.Show(excel);
OleDbCommand cmd = new OleDbCommand(excel, baglan);
cmd.ExecuteNonQuery();
Let me explain simply :
yenidosya : is excel files name
sheetadi : is sheets name ( i am taking it from somewhere else )
In sheetadi i have ' at start and end. so i trim it
i is my column number and it can change parametric
with shtsrg i want to merge sheetname and column number ( it's also my table name )
I used excel string for make table name parametric
I'm trying to use this method :
How to update single cell of excel sheet using oledb connection, | The ASP.NET Forums[
^]
But it gives me an error :
Syntax error in UPDATE statement
Do you have any suggestion about where is Syntax error , or which block has problem ?
What I have tried:
How to update single cell of excel sheet using oledb connection, | The ASP.NET Forums[
^]