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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

OLEDB excel import only selecting "string" values.

Status
Not open for further replies.

JustBarno

Programmer
Jun 21, 2004
46
0
0
US
Dates, and number fields are just empty cells in the DataTable resulting from the select statement.

Any idea what might be wrong?
 
Dim sConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;" _
& "Data Source=" & strPath & strFile _
& ";" & "Extended Properties=Excel 8.0;"

' Create the connection object by using the preceding connection string.
Dim objConn As New OleDbConnection(sConnectionString)

' Open connection with the database.
objConn.Open()

' The code to follow uses a SQL SELECT command to display the data from the worksheet.

' Create new OleDbCommand to return data from worksheet.
Dim objCmdSelect As New OleDbCommand("SELECT * FROM [" & strWorkSheetName & "$]", objConn)

' Create new OleDbDataAdapter that is used to build a DataSet
' based on the preceding SQL SELECT statement.
Dim objAdapter1 As New OleDbDataAdapter

' Pass the Select command to the adapter.
objAdapter1.SelectCommand = objCmdSelect

' Create new DataSet to hold information from the worksheet.
Dim oDs As New DataSet

' Fill the DataSet with the information from the worksheet.
objAdapter1.Fill(oDs)

' Clean up objects.
objConn.Close()
Return (oDs)
 
I am having the same problem. In the extended properties of your connection you can specify that there is no header row.. HDR=No;

This doesn't resolve the problem for me, but it might be the problem for some with missing data. I've tried converting the datatypes to strings in the SELECT statement to no avail. Anyone?
 
Ahh I just found it. In the extended properties if I set IMEX=1 then it works. I have no idea why, but I saw it mentioned somewhere else on this forum and it fixed it.

-Captain Jim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top