-
can not fill dataset
The following is my code:
Dim sql As String = "Select * From tblStudnet"
Dim conString As String = "Driver={MySQL ODBC 3.51 Driver};SERVER=localhost;DATABASE=myDatabaseName"
'Create connection object
Dim connection As OdbcConnection = New OdbcConnection(conString)
connection.open()
msgbox"connected"
'Create data connection object
Dim daStudent As OdbcDataAdapter = New OdbcDataAdapter(sql, connection)
'Create a dataset object and fill with data using data adapter's Fill method
Dim dsStudent As DataSet = New DataSet()
dsStudent.Clear()
daStudent.Fill(dsStudent, "tblNewTable")
I got error at last line:
"An unhandled exception of type 'Microsoft.Data.Odbc.OdbcException' occurred in microsoft.data.odbc.dll
Additional information: System error."
Can you help?
-
Try adding a semicolon to the end of your connectionstring:
Dim conString As String = "Driver={MySQL ODBC 3.51 Driver};SERVER=localhost;DATABASE=myDatabaseName;"
-
thanks for your reply, Edneeis.
I tried your suggestion, no luck. I added a msgbox after the connection was open, it seems the connection was opened successfully.
-
Check the stacktrace of the exception to get which line is giving you trouble. Also make sure that you spelled the tablename right and there is no need to clear the dataset since you just created it.
-
I thought the same thing about clearing it before using, but have seen a few suggestions that it causes greif with binding if you dont.
Check the exception info as Edneeis says, you have a few things you can look at: (slight edit from the help file)
e.Errors(i).Message
e.Errors(i).NativeError.ToString()
e.Errors(i).Source
e.Errors(i).SQLState
-
I did it. Thank you so much!