Problems connecting ODBC

Harlequin

Member
Joined
Dec 20, 2008
Messages
6
Programming Experience
Beginner
I'm trying to connect to a mySql database using VB 2008.
I have created a test database called 'bank'.
I have created an dsn file called mySQLODBC.
The test connection for the ODBC is successful.

my problem is in connecting and reading the data from VB

I have input the following into a console project.

VB.NET:
Imports System
Imports System.Data
Imports System.Data.Odbc

Module OdbcProvider
    Sub Main()


        Dim connString As String = "dsn=c:\\Documents and settings\Hugh\My Documents\SQL\mySqlODBC.dsn"

        Dim sql As String = "Select fname from Person"

        Dim reader As OdbcDataReader = Nothing

        Try

            Dim conn As New OdbcConnection(connString)
            conn.Open()

            Dim cmd As New OdbcCommand(sql, conn)


            Console.WriteLine("this shows" & "ODBC Provider")
            reader = cmd.ExecuteReader()
            Console.ReadLine()


        Catch e As exception
            Console.writeline("Error: ", e)

        Finally
            Reader.close()
        End Try
    End Sub
End Module

The Database is bank, the dsn file is mySqlODBC, the Table is Person adn I'm trying to read the fname field.

I'll appreciate all help.
Thanks
H
 
You're creating the data reader but you aren't reading any data. You have to call Read and then get the data from the data reader. I suggest that you read the documentation for the OdbcDataReader class so you understand how it works. It provides a code example that demonstrates what I said.
 
Back
Top