Update Excel File Using ADO .Net
The following code is not updating the excel file passed in the FileName parameter. No exceptions are being thrown.
public void UpdateExcelFile(string SomeFile)
{
OleDbConnection Connection = new OleDbConnection();
try{
OleDbCommand Command = new OleDbCommand();
string ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " + SomeFile + ";Extended Properties=Excel 8.0;";
Connection.ConnectionString = ConnectionString;
Connection.Open();
string MyCommandText = "UPDATE [Sheet1$A1:A1] SET F1 = 'SomethingNew'";
Command.CommandText = MyCommandText;
Command.Connection = Connection;
Command.ExecuteNonQuery();
}
catch(Exception ex)
{}
finally
{ Connection.Close() }
}
|