How can we upload excelsheet into sqlserver 2008 using asp.net.
"just click on uploading ,we see the data using grid view at a time it save on database.
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
Joginder BangerRank #360 · 7K reputationPosted Nov 25, 2014, 2:59 AM EST
try this code,
string path = string.Concat((Server.MapPath("~/admin/Import/" + FileUpload.FileName)));
FileUpload.PostedFile.SaveAs(path);
string FileExt = System.IO.Path.GetExtension(FileUpload.FileName);
OleDbConnection OleDbcon = new OleDbConnection();
OleDbcon = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties=Excel 12.0;");
OleDbcon.Open();
OleDbCommand cmd = new OleDbCommand("SELECT * FROM [Sheet1$]", OleDbcon);
OleDbDataAdapter objAdapter1 = new OleDbDataAdapter(cmd);
conn.Open();
DbDataReader dr = cmd.ExecuteReader();
dt.Load(dr);
if (dt.Rows.Count > 0)
{
for (int i = 0; i < dt.Rows.Count; i++)
{
//do stuff here like upload data one by one
}
//call here your bind gridview function
}