Link to home
Start Free TrialLog in
Avatar of padi89
padi89Flag for Austria

asked on

How do I export Excel Table into the correct Columns of Datagridview

Hi everybody,

I have to export an Excel table in a datagridview. The problem is, after adding Column Headers to the dgv, the Excel table starts in the first column after my defined column headers.

So please tell me, how do I get the Excel table in the first colum with the header "Bauteilart"(like in the picture).

Thx.
Kind regards



public void LoadList()
        {
            try
            {                
                string connection1 = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=";
                string connection3 = ";Extended Properties=\"Excel 8.0;HDR=No;\"";
                string connectionString = connection1 + "C:\\List.xls" + connection3;

                OleDbConnection cnn = new OleDbConnection(connectionString);
                OleDbDataAdapter da;                
                DataSet ds;

                da = new OleDbDataAdapter("Select * from [List$]", cnn);
                ds = new DataSet("Bl");                
                da.Fill(ds, "Bl");
                dgv_Order.AutoGenerateColumns =false;
                dgv_Order.DataSource = ds.Tables[0];
                cnn.Close();
                da.Dispose();
                ds.Dispose();
                Initialize_dgv_Order();            
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());                
            }
        }

Open in new window

dgv-ee.bmp
ASKER CERTIFIED SOLUTION
Avatar of Mathiyazhagan
Mathiyazhagan
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of padi89

ASKER

Hi,

I already thought that it have to be a easy solution, but you've shown me the way!

Thanks a lot!
Padi
Avatar of padi89

ASKER

Hi,

I arlready thought that the solution sould be easy, but you've shown me the way.
Thanks for the solution.