OLEDB Connection Problem

darkznet

New member
Joined
Jul 25, 2003
Messages
4
I tried using OLEDB to connect to my access database. But i get some error when i tried to run the application.

Under the line myReader = myCommand.ExecuteReader() it gave me an error saying that

An unhandled exception of type System.Data.OleDb.OleDbException occurred in system.data.dll


How can i solved this problem ?

Code:
       Dim myConnString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Inetpub\wwwroot\KW\db1.mdb"
        Dim mySelectQuery As String = "SELECT * FROM User"
        Dim myConnection As New OleDbConnection(myConnString)
        Dim myCommand As New OleDbCommand(mySelectQuery, myConnection)
        myConnection.Open()
        Dim myReader As OleDbDataReader
        myReader = myCommand.ExecuteReader()
        While myReader.Read()
            Console.WriteLine(myReader.GetInt32(0).ToString() + ", " _
               + myReader.GetString(1))
        End While
        myReader.Close()
        myConnection.Close()
 
are you sure the table " User " is there? i just tried your code on 1 of my dbs ( calling Table1 ) and it worked fine :
Code:
Imports System.Data.OleDb
 /// top of code page.
///////////////////////////

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim myConnString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\MyDb.mdb"
        Dim mySelectQuery As String = "SELECT * FROM Table1"
        Dim myConnection As New OleDbConnection(myConnString)
        Dim myCommand As New OleDbCommand(mySelectQuery, myConnection)
        myConnection.Open()
        Dim myReader As OleDbDataReader
        myReader = myCommand.ExecuteReader()
        While myReader.Read()
            Console.WriteLine(myReader.GetInt32(0).ToString() + ", " _
               + myReader.GetString(1))
        End While
        myReader.Close()
        myConnection.Close()

    End Sub
 
Back
Top