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).

Kind regards

public void LoadList()
                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];
            catch (Exception ex)

Open in new window

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Hi, The problem is you have added columns in Datagridview with headertext and not not configured "DataPropertName" property. this property only maps the datatable column with gridview columns. so, it will consider HeaderText as datapropertyname and searches for them in datatable.hence the datatable does not them,it will displayed empty and normal table popualted.To avoid is, we  should Remove columns in designer.after populating datagridview,change the column name as:
 dgv_Order.Columns["F1"].HeaderText = "bauteilart";

hope this helps

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
padi89Author Commented:

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

Thanks a lot!
padi89Author Commented:

I arlready thought that the solution sould be easy, but you've shown me the way.
Thanks for the solution.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.