BobNoobGuy
BobNoobGuy

Reputation: 1645

OleDBDataAdapter Fill error Select statement using VB.net and MS access

Help, My code fails on da.fill(dt). The error says OleDBexception was unhandled no value given for one or more required parameter

My code

        Dim Conn As OleDb.OleDbConnection = New OleDb.OleDbConnection
        Dim connString As String
        Dim da As OleDb.OleDbDataAdapter
        Dim dt As New DataTable
        Dim oCmd As OleDb.OleDbCommand
        Dim SQLString As String

        connString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source =" & sRemoteAccessFolder & "Projects.MDB"
        Conn.ConnectionString = connString
        Conn.Open()
        SQLString = "select * from tblProjects where ProjectNumber='10100'"


        da = New OleDb.OleDbDataAdapter(SQLString, Conn)
        da.Fill(dt)

Any idea?

thx u

Upvotes: 1

Views: 3622

Answers (3)

Subhash Tiwary
Subhash Tiwary

Reputation: 1

The same thing happened in my project as well.

SQLString = "select * from tblProjects where ProjectNumber='10100'"

I followed the same and concluded this way it helped me. The correct statement which worked for me is

SQLString = "select * from tblProjects where [ProjectNumber]='10100'"

Upvotes: 0

LarsTech
LarsTech

Reputation: 81610

This line has problems probably:

SQLString = "select * from tblProjects where ProjectNumber='10100'"

The field ProjectNumber has to match what is in the table. If there is a space, then you need to include brackets:

SQLString = "select * from tblProjects where [Project Number]='10100'"

If it's a numeric field, then drop the quotes:

SQLString = "select * from tblProjects where [Project Number]=10100"

If you still have errors, then make sure you have a table called tblProjects in the database.

As always, make sure to use Parameters instead of doing the sql statement completely by hand. That will avoid potential sql injection issues.

Upvotes: 1

gmail user
gmail user

Reputation: 2783

I haven't used it for long time. But may be do as follow.

  connString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source =" & sRemoteAccessFolder &  "Projects.MDB"
  Conn.ConnectionString = connString
  Conn.Open()

  Dim oCmd As new OleDb.OleDbCommand
  oCmd.CommandText= "select ...."
  Dim da As OleDb.OleDbDataAdapter
  Dim dt As New DataTable

  da = New OleDb.OleDbDataAdapter(oCmd)
  da.Fill(dt)

Upvotes: 0

Related Questions