Hi
I tried to use following code to access MySQL database but the error 'Object reference not set to an instance of an object' was happened:
[code=vb]
Dim MyConString As String = "DRIVER={My SQL ODBC 3.51 Driver}; SERVER=localhos t; DATABASE=xxxx; UID=xxxx; PASSWORD=xxxx; OPTION=3"
Dim MyConnection As New System.Data.Odb c.OdbcConnectio n(MyConString)
Dim SQL As String = "SELECT * FROM registration_co de"
Dim MyCommand As New System.Data.Odb c.OdbcCommand
MyCommand = New System.Data.Odb c.OdbcCommand(S QL, MyConnection)
MyConnection.Op en()
Dim dr As System.Data.Odb c.OdbcDataReade r
dr = MyCommand.Execu teReader(System .Data.CommandBe havior.CloseCon nection Or System.Data.Com mandBehavior.Si ngleResult)
While dr.Read()
...
Loop
MyConnection.Cl ose()
[/code]
The error shown as like:
Is there anybody know where my codes wrong?
Thanks
Gary
I tried to use following code to access MySQL database but the error 'Object reference not set to an instance of an object' was happened:
[code=vb]
Dim MyConString As String = "DRIVER={My SQL ODBC 3.51 Driver}; SERVER=localhos t; DATABASE=xxxx; UID=xxxx; PASSWORD=xxxx; OPTION=3"
Dim MyConnection As New System.Data.Odb c.OdbcConnectio n(MyConString)
Dim SQL As String = "SELECT * FROM registration_co de"
Dim MyCommand As New System.Data.Odb c.OdbcCommand
MyCommand = New System.Data.Odb c.OdbcCommand(S QL, MyConnection)
MyConnection.Op en()
Dim dr As System.Data.Odb c.OdbcDataReade r
dr = MyCommand.Execu teReader(System .Data.CommandBe havior.CloseCon nection Or System.Data.Com mandBehavior.Si ngleResult)
While dr.Read()
...
Loop
MyConnection.Cl ose()
[/code]
The error shown as like:
Code:
Object reference not set to an instance of an object. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Thanks
Gary
Comment