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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
nagendra prasadPosted Nov 24, 2014, 8:20 AM
Joginder BangerPosted Nov 24, 2014, 1:05 AM
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);