Quantcast
Channel: Oracle, MySQL, Sybase, Informix and other databases
Viewing all articles
Browse latest Browse all 1350

Writign line of excel file : I need help to make working my code

$
0
0

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)


Viewing all articles
Browse latest Browse all 1350

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>