Hiiii
I need to store the MS Excel sheet as Entity into the database using C#
please suggest me
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 23, 2014, 8:05 PM EST
I have done it before some time it's may help you.
string holdcolumnname = "";
//Array.ForEach(Directory.GetFiles((Server.MapPath("~/admin/Import/"))),
File.Delete); // Delete for all file in the Import Directory.
string path = string.Concat((Server.MapPath("~/admin/Import/" +
youfileName)));
directoryName.PostedFile.SaveAs(path);
string temp = Path.GetExtension(path);
if (temp == ".xls")
comman = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data
Source=" + path + ";Extended Properties=\"Excel 8.0;HDR=YES;IMEX=1;\";");
else
comman = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data
Source=" + path + ";Extended Properties=\"Excel 12.0;HDR=YES;\";");
comman.Open();
OleDbCommand cmd = new OleDbCommand("SELECT * FROM [Sheet1$]",
comman);
conn.Open();
DbDataReader dr = cmd.ExecuteReader();
dt.Load(dr);
nagendra prasad30 reputationPosted Nov 24, 2014, 3:20 AM EST