troubleshooting Question

import datatable to sql

Avatar of Seven price
Seven priceFlag for United States of America asked on
.NET Programming
3 Comments1 Solution254 ViewsLast Modified:
I have this datatable display in a gridview. I want to import it into a sql database after.
 protected void btnDetails_Click(object sender, EventArgs e)

            string path = Server.MapPath("~/UploadFiles/" + fupExcel.FileName);
            if (!File.Exists(path.ToString().ToUpper()))

             OleDbConnection conn = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" +
              path + ";Extended Properties='Excel 12.0;HDR=YES;IMEX=1;';");
            OleDbCommand cmd = new OleDbCommand(); ;
            OleDbDataAdapter oleda = new OleDbDataAdapter();
            DataSet ds = new DataSet();

            // selecting distict list of EmpNo 
                       cmd.Connection = conn;
            cmd.CommandType = CommandType.Text;
            cmd.CommandText = "SELECT * FROM [1108$]";
            //[Sheet1$] is Excel sheet name in your file
            oleda = new OleDbDataAdapter(cmd);
            oleda.Fill(ds, "dsSlno");
            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                grvData.DataSource = ds.Tables[0].DefaultView;
                grvData.DataSource = null;


Open in new window

Ess Kay

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros