Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
How do I tell a DataGridView NOT to create column headers from the
first row of a data table using an Excel datasource?
Posted 20-Apr-13 3:43am
Edited 20-Apr-13 5:31am
Mehdi Gholam250.3K
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Depending on how you're bringing the data into your DataGridView, you would probably specify it in your connection string using "HDR=NO".
 
If you're using a normal *.xlsx file, then your connection string would look something like the one below:
 
"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=c:\myFolder\myExcel2007file.xlsx;
Extended Properties="Excel 12.0 Xml;HDR=NO";"
 
Other variations of the above are shown at connectionstrings.com.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Thanks for your Reply traciray.
 
Actually i had specified that HDR=No in my connection string but still it was taking my 1st dataTables row as column header.
 

There was also one more parameter in my connection string IMEX which was set to 2. this when i changed to 1 it worked for me.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 520
1 Maciej Los 290
2 Richard MacCutchan 265
3 BillWoodruff 265
4 Suraj Sahoo | Coding Passion 155
0 OriginalGriff 8,764
1 Sergey Alexandrovich Kryukov 7,437
2 DamithSL 5,639
3 Maciej Los 5,279
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web04 | 2.8.1411028.1 | Last Updated 23 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100