Hi, i have a part of code wher i upload the file xls, which works fine
and after i found a code to read my xls file uploaded
var fileNametouse = "@" + path; var connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + fileNametouse + ";Extended Properties=\"Excel 12.0;IMEX=1;HDR=NO;TypeGuessRows=0;ImportMixedTypes=Text\""; ; using (var conn = new OleDbConnection(connectionString)) { conn.Open(); var sheets = conn.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Tables, new object[] { null, null, null, "TABLE" }); using (var cmd = conn.CreateCommand()) { cmd.CommandText = "SELECT * FROM [" + sheets.Rows[0]["TABLE_NAME"].ToString() + "] "; var adapter = new OleDbDataAdapter(cmd); var ds = new DataSet(); adapter.Fill(ds); // My foreach it is not working because he cannot work with variables type : System.data.oledb.OleDbDataAdapter foreach (var marketinglist in adapter) { //Add each email inside my db (i am not sure this is the way to add record) MarketingEmail marketingemail = db.MarketingEmails.Add(marketingemail); marketingemail.MarketingEmailEMAIL = marketinglist.CELL Column 1
marketingemail.MarketingEmailName = marketinglist.CELL Column 2 db.SaveChanges(); } } }
My foreach it is not working because he cannot work with variables type : System.data.oledb.OleDbDataAdapter
how can i do a foreach of my styleshet and take each record an copy it in my table (in my file excel ui have 2 column : email and name)