Exporting and Importing data
How to exporting and importing data from sql-server database through excel sheet in asp.net.
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.
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
Posted Aug 31, 2009, 10:52 AM EDT
carle lai40 reputationPosted Sep 22, 2009, 6:37 PM EDT
the code for import excel :
code:
private DataTable getDataFromXLS(string path, string blad,string headers)
{
try
{
string strConnectionString =string.Empty;
strConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source="+path+";" +
"Extended Properties=" + (char)34 + "Excel 8.0;HDR=Yes;IMEX=1;" + (char)34;
OleDbConnection cnCSV =new OleDbConnection (strConnectionString);
cnCSV.Open();
OleDbCommand cmdSelect = new OleDbCommand (@"SELECT " +headers+ " FROM ["+blad+"]", cnCSV);
OleDbDataAdapter daCSV = new OleDbDataAdapter();
daCSV.SelectCommand = cmdSelect;
DataTable dtCSV = new DataTable ();
daCSV.Fill(dtCSV);
cnCSV.Close();
daCSV = null;
return dtCSV;
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
return null;
}
}