Hey I have this piece of code:
Hey I have this piece of code, I put the dataTable that is returned in a dataGrid, Everything works fine when my data starts on the first row of the excel sheet, but when my data stands somewhere else in the excel sheet for example in the middle of page 1 of an excel sheet. I get F1 to F10 as columnheaders and my data is in the midle of the datagrid and all my headers just stand in the middle of the datagrid without the last one, that's just gone. What am i doing wrong or how can i make sure that my date get's put on the first row of the datagrid with correct columnheaders even if the data i fetch is in the middle of the excel sheet?
public ExcelReader() { connection = new OleDbConnection(); connection.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\xxxxx\xxxxxx\xxxxxx_xxxxx\xxxxx.ExcelReader\Excel workmap\xxxxx.xlsx" + @";Extended Properties=""Excel 8.0;HDR=YES;ImportMixedTypes=Text;TypeGuessRows=0"""; } public DataTable readExcelWorkBook() { command = new OleDbCommand("SELECT * " + "FROM [Blad1$]",connection); DataSet dsGebruikers = new DataSet(); OleDbDataAdapter adapter = new OleDbDataAdapter(command); adapter.Fill(dsGebruikers); DataTable dataTable = dsGebruikers.Tables[0]; return dataTable; }
This is how I fill the form:
public Form1() { InitializeComponent(); reader = new ExcelReader(); } private void btnLoadData_Click(object sender, EventArgs e) { dataGridViewUsers.DataSource = reader.readExcelWorkBook(); }