...

View Full Version : C#\\ trying to insert data to Excel file using OLEDB



OnTarget
08-17-2012, 11:10 PM
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

http://social.msdn.microsoft.com/Forums/getfile/153707

anybody knows why and what to do?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum