N
Nickneem
I'm having a hard time creating a dataset from an excel worksheet
[WORKSHEET]
Auto Drop DEB Leverdatum
1 1 33370 9-11-2005
1 2 30518 9-11-2005
11 10 D9930 9-11-2005
12 1 5330 9-11-2005
12 2 18050 9-11-2005
[VB.Net function]
Public Function CreateDataSetFromExcel(ByVal MyFileName As String,
ByVal MyFilePath As String) As DataSet
Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=" & MyFilePath & MyFileName & ";Extended Properties=""Excel
8.0;HDR=Yes;IMEX=1"""
Dim objConn As OleDbConnection = New OleDbConnection(strConn)
Dim objComm As OleDbCommand = New OleDbCommand("select
leverdatum, deb, auto, drop from [drop$]", objConn)
Dim MyAdapter As New OleDbDataAdapter(objComm)
Try
Dim TempDs As New DataSet
objConn.Open()
MyAdapter.Fill(TempDs)
objConn.Close()
Return TempDs
Catch ex As Exception
objConn.Close()
End Try
End Function
It's because of the mixed datacolumns in column "DEB".
According to http://www.connectionstrings.com/ adding IMEX=1 should do
the trick (force to read the column as text) but it won't.
I still get system.dbnull for my D9930 value:
? tmpds.Tables(0).Rows(2).ItemArray
{Length=4}
(0): #11/9/2005#
(1): {System.DBNull}
(2): 11.0 {Double}
(3): 10.0 {Double}
Thanks in advance,
Mike
[WORKSHEET]
Auto Drop DEB Leverdatum
1 1 33370 9-11-2005
1 2 30518 9-11-2005
11 10 D9930 9-11-2005
12 1 5330 9-11-2005
12 2 18050 9-11-2005
[VB.Net function]
Public Function CreateDataSetFromExcel(ByVal MyFileName As String,
ByVal MyFilePath As String) As DataSet
Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=" & MyFilePath & MyFileName & ";Extended Properties=""Excel
8.0;HDR=Yes;IMEX=1"""
Dim objConn As OleDbConnection = New OleDbConnection(strConn)
Dim objComm As OleDbCommand = New OleDbCommand("select
leverdatum, deb, auto, drop from [drop$]", objConn)
Dim MyAdapter As New OleDbDataAdapter(objComm)
Try
Dim TempDs As New DataSet
objConn.Open()
MyAdapter.Fill(TempDs)
objConn.Close()
Return TempDs
Catch ex As Exception
objConn.Close()
End Try
End Function
It's because of the mixed datacolumns in column "DEB".
According to http://www.connectionstrings.com/ adding IMEX=1 should do
the trick (force to read the column as text) but it won't.
I still get system.dbnull for my D9930 value:
? tmpds.Tables(0).Rows(2).ItemArray
{Length=4}
(0): #11/9/2005#
(1): {System.DBNull}
(2): 11.0 {Double}
(3): 10.0 {Double}
Thanks in advance,
Mike