D
Drygast
I'm newbie to programming and it seems I'm stuck on this problem....
the code:
_____________________________
Private Sub fetchOrder()
If txtOrdernummer.Text <> "" Then
Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\temp\dummy.mdb"
Dim cmd As New OleDbCommand("Select [Order].* From [Order] Where
Order.Ordernummer = " & txtOrdernummer.Text & "", New
OleDbConnection(strConn))
cmd.Connection.Open()
Dim myReader As OleDbDataReader = cmd.ExecuteReader()
Try
While myReader.Read()
lblButik.Text = myReader.GetInt32(2).ToString
lblAnkom.Text = myReader.GetDateTime(3).ToShortDateString
If myReader.GetDateTime(6).ToShortDateString <> "" Then
lblSkickad.Text = myReader.GetDateTime(6).ToShortDateString
End If
End While
Finally
myReader.Close()
cmd.Connection.Close()
End Try
Else
MsgBox("Ange Ordernummer!")
txtOrdernummer.Focus()
End If
End Sub
___________________
The Problem:
The code gets data from an access database, it works like a charm if there
is a value in the field.
However, when the field is null in the database I get the following error:
An unhandled exception of type 'System.InvalidCastException' occurred in
system.data.dll
Additional information: Specified cast is not valid.
It seems like there's something wrong with this line:
"If myReader.GetDateTime(6).ToShortDateString <> "" Then"
but I can't figure it out..
Regards
/Drygast
the code:
_____________________________
Private Sub fetchOrder()
If txtOrdernummer.Text <> "" Then
Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\temp\dummy.mdb"
Dim cmd As New OleDbCommand("Select [Order].* From [Order] Where
Order.Ordernummer = " & txtOrdernummer.Text & "", New
OleDbConnection(strConn))
cmd.Connection.Open()
Dim myReader As OleDbDataReader = cmd.ExecuteReader()
Try
While myReader.Read()
lblButik.Text = myReader.GetInt32(2).ToString
lblAnkom.Text = myReader.GetDateTime(3).ToShortDateString
If myReader.GetDateTime(6).ToShortDateString <> "" Then
lblSkickad.Text = myReader.GetDateTime(6).ToShortDateString
End If
End While
Finally
myReader.Close()
cmd.Connection.Close()
End Try
Else
MsgBox("Ange Ordernummer!")
txtOrdernummer.Focus()
End If
End Sub
___________________
The Problem:
The code gets data from an access database, it works like a charm if there
is a value in the field.
However, when the field is null in the database I get the following error:
An unhandled exception of type 'System.InvalidCastException' occurred in
system.data.dll
Additional information: Specified cast is not valid.
It seems like there's something wrong with this line:
"If myReader.GetDateTime(6).ToShortDateString <> "" Then"
but I can't figure it out..
Regards
/Drygast