OleDb connection question! Pls help!!!

albertkhor

Well-known member
Joined
Jan 12, 2006
Messages
150
Programming Experience
Beginner
VB.NET:
[/COLOR][/SIZE]
[COLOR=black][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2][COLOR=#000000] DSexcel [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#000000] System.Data.DataSet[/COLOR]
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] [COLOR=black]ExcelCommand[/COLOR] [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [COLOR=black]System.Data.OleDb.OleDbDataAdapter[/COLOR]
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] [COLOR=black]ExcelConnection [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [COLOR=black]System.Data.OleDb.OleDbConnection[/COLOR]
[/SIZE][/COLOR][/COLOR][COLOR=black][COLOR=#0000ff][/COLOR][/COLOR] 
[COLOR=black][COLOR=#0000ff]If[/COLOR][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].OpenFileDialog1.ShowDialog() = DialogResult.OK [/SIZE][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE][SIZE=2]
[/SIZE][SIZE=2][COLOR=#0000ff]Try
[/COLOR][/SIZE][SIZE=2]ExcelConnection = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] System.Data.OleDb.OleDbConnection( _
"provider=Microsoft.Jet.OLEDB.4.0; " & _
"data source=" & OpenFileDialog1.FileName & " ; " & _
"Extended Properties=Excel 8.0;")
ExcelCommand = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] System.Data.OleDb.OleDbDataAdapter("select * from [Sheet1$]", ExcelConnection)
DSexcel = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] System.Data.DataSet
ExcelCommand.Fill(DSexcel)
DataGridCopy = DSexcel.Tables(0)
ExcelConnection.Close()
[/SIZE][SIZE=2][COLOR=#0000ff]Catch[/COLOR][/SIZE][SIZE=2] ex [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Exception
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Try[/COLOR][/SIZE]
[COLOR=#0000ff]End If[/COLOR]
[/COLOR][SIZE=2][COLOR=black]

when i using this connection, i found out that the data i get from excel is start with second row which mean the first row data is not in the DSexcel.Tables (i use DataGridCopy.Rows(0).Items(0).ToString() to check). How to get all the data in excel can someone teach me!
Note: the first row data is not save on DSexcel but it become header in datagrid
 
I'm guessing that the default is to assume that the first row of data is column headers. You have to use your connection string to specify otherwise. Take a look at www.connectionstrings.com for an example of a connection string for Excel. You can edit it to specify that your data has no column headers.
 
Back
Top