MySQL, VB.NET, ADO.NET, and DATETime issue
Posted by: mbmonk
Date: September 27, 2004 06:40PM

There is a complete and better description of my problem at: http://www.vbcity.com/forums/topic.asp?tid=80643

Here is more a less a repost of that topic:

OK here is the Error I recieve

An unhandled exception of type 'System.FormatException' occurred in system.data.dll

Additional information: The DateTime represented by the string is out of range.


Overview I am trying to pull a bunch of dates from a MySQL Table.

Here is the Select statement I am trying to execute in the function defined below (NOTE: database name and table name have been changed to generic names):
"SELECT LOAD_NO, DEL_DATE1, DEL_DATE2, DEL_DATE3, DEL_DATE4, DEL_DATE5, DEL_DATE6 FROM database.tablename;"

Here is the VB.NET code that is kicking me an error:

Public Function ConnectAndExecuteQuery(ByVal strSQL As String, ByVal Username As String, ByVal Password As String, ByVal Host As String, ByVal par_DBName As String) As DataTable
'Function connects and useing Username and Password, then executes the query and returns the DataTable with
'results
Dim myCon As MySqlConnection
Dim ds As DataSet = New DataSet
myCon = New MySqlConnection
ConnectToMySQL(Username, Password, Host, par_DBName, myCon)
Dim da As MySqlDataAdapter = New MySqlDataAdapter(strSQL, myCon)
'CRASHES AT NEXT LINE da.Fill(ds)
da.Fill(ds)
Dim tbl As DataTable = ds.Tables(0)
myCon.Close()
Return tbl
End Function

Public Function ConnectToMySQL(ByVal Username As String, ByVal Password As String, ByVal Host As String, ByVal DataBaseName As String, ByVal DBConnection As MySqlConnection) As Boolean


DBConnection.ConnectionString = "Server=" & Host & ";" & "Database=" & " " & DataBaseName & ";" _
& "user id=" & Username & ";" & "password='" & Password & "';"


If (DBConnection.State = ConnectionState.Closed) Then
Try
DBConnection.Open()
Catch e As Exception
Return False
End Try

Return True
End If

Return True
End Function

END OF CODE

Here is an example of the data that I can get from the table if I execute the Select statement in the mysql command line client. I am unable to find out what exact row of data is causing the crash from the table. I am just giving the following data as an example of the data.

/ 44569 / 2004-07-13 / 2004-07-14 / 2004-07-14 / NULL / NULL / NULL /

Note: I am using the following Data Provider: http://www.mysql.com/products/connector/net/

BTW, This code normally works, this is the first time I have had an issue with it.
Any help is appreciated and please let me know if I can add more information


Options: ReplyQuote


Subject
Written By
Posted
MySQL, VB.NET, ADO.NET, and DATETime issue
September 27, 2004 06:40PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.