- Home /
trying to insert data to Excel file using OLEDB
I want a button in c# form to be able to insert data to excel table.
this is what i did..
try
{
System.Data.OleDb.OleDbConnection MyConnection;
System.Data.OleDb.OleDbCommand myCommand = new System.Data.OleDb.OleDbCommand();
string sql = null;
MyConnection = new System.Data.OleDb.OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;Data Source='C:\\Users\\Miko\\Documents\\WeightWatchers - Copy\\TrackingLoss.xlsx';Extended Properties=Excel 8.0;");
MyConnection.Open();
myCommand.Connection = MyConnection;
sql = "Insert into [Sheet1] (Date,Loss) values(y,x)";
myCommand.CommandText = sql;
myCommand.ExecuteNonQuery();
MyConnection.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
when im trying it this window is open
anybody knows why and what to do?
Comment
Answer by MyUnitydream · Sep 12, 2018 at 05:24 AM
you can use Uni-Excel Package for Read, Write, and edit excel files
Your answer
Follow this Question
Related Questions
Write Data From List To CSV File 0 Answers
c# unable to create datatable, using System.Data not an accepted assembly reference 1 Answer
Creating a table 2 Answers
CSV Reader delimiter problem 1 Answer