hi
how can i export data from excel to sql server database.
can any body tell me the procedure how to do this and which is the better way to do this?
hi
how can i export data from excel to sql server database.
can any body tell me the procedure how to do this and which is the better way to do this?
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Sen14 reputationPosted Jul 15, 2008, 2:26 AM EDT
using System.Data.OleDb;
string sheetName = "Sheet1";
string filePath="C:\\temp.xls";
DataTable myDataTable = new System.Data.DataTable();
DataSet dataSet1 = new DataSet();
OleDbDataAdapter oledbAdapterObj;
OleDbConnection connection = new OleDbConnection();
OleDbDataAdapter command = new OleDbDataAdapter();
//connection to read excel file
connection = new System.Data.OleDb.OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;" + "data source='" + filePath + " '; " + "Extended Properties=\"Excel 8.0;HDR=NO;IMEX=1\"");
connection.Open();
command = new System.Data.OleDb.OleDbDataAdapter("select * from [" + sheetName + "$]", connection);
oledbAdapterObj = command;
oledbAdapterObj.Fill(dataSet1);
myDataTable = dataSet1.Tables[0];
for (int row = 0; row < myDataTable.Rows.Count; row++)
{
for (int col = 0; col < myDataTable.Columns.Count; col++)
{
//read data from datatable using
// (myDataTable.Rows[row][col].ToString());
}
//query to insert to sqlserver database
}
kesava reddy6 reputationPosted Jul 15, 2008, 7:04 AM EDT
hi thanks for giving me the sample code
but as i am completely new to this .net please send me the code in for loop
that how to insert into database;