Dear Sir,
I am testing with MySQL, and .NET 2003 to export few records in text format with pipe “|” delimiter. But, unable to make it work. Any help or comments will be greatly appreciated.
VB.NET error "An unhandled exception of type 'System.FormatException' occurred in corelab.mysql.dill
Additional information: IncorrectFormat."
Below is the code for your examination:
Private Sub Download_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Download.Click
Dim MyConnString As String = "User Id=testUser;Host=localhost;Database=main;Password=st9041%SSpdW;"
Dim mySelectQuery As String = "SELECT name,phone,fax,address,city,state,zip FROM main.person"
Dim myConnection As New MySqlConnection(MyConnString)
Dim myCommand As New MySqlCommand(mySelectQuery, myConnection)
myConnection.Open()
Dim myReader As MySqlDataReader = myCommand.ExecuteReader()
Dim saveDialog As New SaveFileDialog
Dim myResult As DialogResult
saveDialog.Filter = "Text File (*.txt) | *.txt|All files (*.*)|*.*"
myResult = saveDialog.ShowDialog
FileOpen(1, saveDialog.FileName, OpenMode.Output)
Try
While myReader.Read()
WriteLine(myReader.GetInt32(0).ToString() + ", " _
+ myReader.GetString(1))
End While
Finally
myReader.Close()
myConnection.Close()
End Try
FileClose(1)
If myResult = DialogResult.OK Then
MsgBox("Saving: " + saveDialog.FileName)
End If
End Sub
Please accept my apologies, if this is not the proper place to post this issue.
Thank you,
Sam
Export list code - IncorrectFormat.
Re: Export list code - IncorrectFormat.
You try to get int value from name field (myReader.GetInt32(0)).
As usual name field holds a string. Probably you would like to retrieve a number of the record. Please pay attention to mySelectQuery.
As usual name field holds a string. Probably you would like to retrieve a number of the record. Please pay attention to mySelectQuery.
Export code.
Hi All,
Below is the code that works:
Below is the code that works:
Code: Select all
Private Sub Download_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Download.Click
Dim MyConnString As String = "User Id=testUser;Host=localhost;Database=main;Password=st9041%SSpdW;"
Dim mySelectQuery As String = "SELECT name,phone,fax,address,city,state,zip FROM main.person"
Dim myConnection As New MySqlConnection(MyConnString)
Dim myCommand As New MySqlCommand(mySelectQuery, myConnection)
myConnection.Open()
Dim myReader As MySqlDataReader = myCommand.ExecuteReader()
Dim saveDialog As New SaveFileDialog
Dim myResult As DialogResult
saveDialog.Filter = "Text File (*.txt) | *.txt|All files (*.*)|*.*"
myResult = saveDialog.ShowDialog
FileOpen(1, saveDialog.FileName, OpenMode.Output)
Try
While myReader.Read()
Dim name As String = myReader.GetString(myReader.GetOrdinal("name"))
Dim phone As String = myReader.GetString(myReader.GetOrdinal("phone"))
Dim fax As String = myReader.GetString(myReader.GetOrdinal("fax"))
Dim address As String = myReader.GetString(myReader.GetOrdinal("address"))
Dim city As String = myReader.GetString(myReader.GetOrdinal("city"))
Dim state As String = myReader.GetString(myReader.GetOrdinal("state"))
Dim zip As String = myReader.GetString(myReader.GetOrdinal("zip"))
Dim myData As String = name & "|" phone & "|" fax & "|" address _
& "|" city & "|" state & "|" zip
WriteLine(1, myData)
End While
Finally
myReader.Close()
myConnection.Close()
End Try
FileClose(1)
If myResult = DialogResult.OK Then
MsgBox("Saving: " + saveDialog.FileName)
End If
End Sub