Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Datagrid Headers - Excel

Status
Not open for further replies.

JasonSummers

Programmer
Sep 11, 2002
26
US
I have a vb.net form that imports data from an excel spreadsheet into a datagrid control. Is it possible to extract the column header names from the datagrid itself, of do I need to figure out how to grab the headers (from excel) during the excel import?

Thanks,

Jason
 
How are you getting the data into the datagrid? Are you putting it in a dataset or datatable?


I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day! Ye has a choice: talk like a pira
 
jebenson,

I'm using an OleDbDataAdapter that fills a dataset using an OleDbConnection to excel. The data adapter selects all * from the first sheet in the excel workbook.

I may be going about this the wrong way. I intended to develop a form that could read from a spreadsheet or csv file, and then update my SQL database. Because the source data may or may not have column headers similar the destination database, I was going to build a drag and drop method of associating source columns with destination columns to build the insert or update statements.

Thanks,

Jason
 
Well, if you Excel data does indeed have column headers, you can loop through a datatable to get the header information:

Dim col As DataColumn

For Each col In DataSet1.Tables(0).Columns
MsgBox(col.ColumnName)
Next

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day! Ye has a choice: talk like a pira
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top