Reputation: 1205
I am have created some function to read data form excel file using, OleDbConnection, OleDbDataAdapter, DataSet. I am able to read data successfully using sheet name, row, column number.
I function using same to update value of excel sheet by passing row and column number.
I need some help,
Thanks in advance.
Upvotes: 0
Views: 6039
Reputation: 96
Unless you have a strong reason for using OleDb for this, I recommend against it. The usage is very limited and archaic and the providers are no longer shipped with Office 2013 or in Windows. NuGet EPPlus and make your life a lot easier.
However, here is an example of how to do an insert and update using OleDb:
using (OleDbConnection cn = new OleDbConnection(connectionString))
{
cn.Open();
using (OleDbCommand cmd1 = new OleDbCommand("INSERT INTO [MySheet$] (COLUMN1, COLUMN2) VALUES ('Count', 1);", cn))
{
cmd1.ExecuteNonQuery();
}
using (OleDbCommand cmd1 = new OleDbCommand("UPDATE [MySheet$] SET COLUMN2 = 5 WHERE ID = 1", cn))
{
cmd1.ExecuteNonQuery();
}
}
Upvotes: 1