Skip to main content
gamedev.net
🔒 Locked

Microsoft Access databse connection string

Started by isiahil 3 replies 1.1k views
Original Post
isiahil
isiahil
Here is the code I try to run in vb .net. I get an error that says the keyword provider is not supported. My connection string is wrong so how should it be?

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        
        Dim sqlConn As New SqlClient.SqlConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\login.mdb")
        Dim sqlCmd As New SqlClient.SqlCommand()
        Dim sqlReader As SqlClient.SqlDataReader

        sqlConn.Open()
        sqlCmd = sqlConn.CreateCommand()
        sqlCmd.CommandText = "SELECT username FROM login"
        sqlReader = sqlCmd.ExecuteReader()



    End Sub
I don't have to do nothing but live and die, everything else i choose to do- I don't know, but my dad says it alot
rmsimpson
rmsimpson
You have to use OleDbConnection and OleDbCommand. The SqlClient namespace is for SQL Server only. Jet is implemented in an OleDb Provider.

Robert
isiahil
isiahil
ok thanx, imma try to test it now
I don't have to do nothing but live and die, everything else i choose to do- I don't know, but my dad says it alot
isiahil
isiahil
I have surpassed that problem but now I get an error that says:

No value given for one or more required parameters.

on the line of code I bolded.

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load                Dim sqlConn As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\login.mdb")        Dim sqlCmd As New OleDb.OleDbCommand()        sqlConn.Open()        sqlCmd = sqlConn.CreateCommand()        sqlCmd.CommandText = "SELECT username FROM login"        Dim sqlReader As OleDb.OleDbDataReader        sqlReader = sqlCmd.ExecuteReader(CommandBehavior.Default)    End Sub
I don't have to do nothing but live and die, everything else i choose to do- I don't know, but my dad says it alot
rmsimpson
rmsimpson
You'll get that error when the name of a column or table is not recognized in Jet. Jet will assume its a parameter name.

Make sure the table "login" exists and the column "username" is in that table.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.