padi89
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
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());
}
}
dgv-ee.bmp
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi,
I arlready thought that the solution sould be easy, but you've shown me the way.
Thanks for the solution.
I arlready thought that the solution sould be easy, but you've shown me the way.
Thanks for the solution.
ASKER
I already thought that it have to be a easy solution, but you've shown me the way!
Thanks a lot!
Padi