mike509123
MIS
I wrote the following code (full source code at the bottom) which writes to cells A7 and B7 in Book1.xls. I am wondering how can I modify the following code so it only write to one cell.
I attempted the following
comOleDBCommand.CommandText = "UPDATE [Sheet1$A7:B7] SET F1 = 5, F2 = 'Cell G3'";
TO
comOleDBCommand.CommandText = "UPDATE [Sheet1$A7] SET F1 = 5";
but get an error. Any ideas?
OleDbConnection conOleDBConnection = new OleDbConnection();
OleDbCommand comOleDBCommand = new OleDbCommand();
conOleDBConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=Book1.xls;Extended Properties=\"Excel 8.0;HDR=NO;\"";
comOleDBCommand.Connection = conOleDBConnection;
conOleDBConnection.Open();
comOleDBCommand.CommandText = "UPDATE [Sheet1$A7:B7] SET F1 = 5, F2 = 'Cell G3'";
comOleDBCommand.ExecuteNonQuery();
conOleDBConnection.Close();
PS if you are trying this code dont forget to add at the top: using System.Data.OleDb;
I attempted the following
comOleDBCommand.CommandText = "UPDATE [Sheet1$A7:B7] SET F1 = 5, F2 = 'Cell G3'";
TO
comOleDBCommand.CommandText = "UPDATE [Sheet1$A7] SET F1 = 5";
but get an error. Any ideas?
OleDbConnection conOleDBConnection = new OleDbConnection();
OleDbCommand comOleDBCommand = new OleDbCommand();
conOleDBConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=Book1.xls;Extended Properties=\"Excel 8.0;HDR=NO;\"";
comOleDBCommand.Connection = conOleDBConnection;
conOleDBConnection.Open();
comOleDBCommand.CommandText = "UPDATE [Sheet1$A7:B7] SET F1 = 5, F2 = 'Cell G3'";
comOleDBCommand.ExecuteNonQuery();
conOleDBConnection.Close();
PS if you are trying this code dont forget to add at the top: using System.Data.OleDb;