Im trying to select data from a MS access database, i have done this for SQL server before with no problem, but now with a Access database i get a run time error for "No value given for one or more required parameters".

Below is my code

Private Sub ViewToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ViewToolStripMenuItem.Click
        Dim cn As OleDbConnection
        Dim cmd As OleDbCommand
        Dim ds As New DataSet
        Dim dt As New DataTable
        Dim da As New OleDbDataAdapter



        Try
            cn = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=I:\doc_cntl\Doc_Control Lists\MS Access Logs\2009 MDL_be.accdb;Persist Security Info=False;")
            'provider to be used when working with access database
            cn.Open()
            cmd = cn.CreateCommand
            cmd.CommandText = "SELECT * FROM [2009 MDL 2] WHERE [DocumentPartNumber] = '" & Trim(txtPartNumber.Text) & "'"
            da.SelectCommand = cmd
            da.Fill(ds, "[2009 MDL 2]")
            dt = ds.Tables("[2009 MDL 2]")

            TextBox1.Text = ds.Tables(0).Rows(0).Item("DrawingLocation").ToString
            TextBox2.Text = ds.Tables(0).Rows(0).Item("DocumentPartNumber").ToString

            cn.Close()
        Catch ex As Exception
            MsgBox("Error: " & ex.Source & ": " & ex.Message, MsgBoxStyle.OkOnly, "Connection Error !!")
        End Try


    End Sub

Thanks for your help in advance.

dakaboguy,
You should check the spelling of your table [2009 MDL 2] and [DocumentPartNumber] field in your query. That is a prime cause of missing parameters error.

Also I noticed the field [DocumentPartNumber] is named for a number and you have it in single quotes in your query. that will throw a datatype mismatch error, but I don't think that's what causing your error.

Hope that helps
Ken

Hi Dakaboguy,

Your connection string for bridging to ACE OLEDB 12 seems ok..

I think the cause might be as described by ken

However check the retrieval

cmd = New OleDbCommand(<commandtext>,<connection>)

Rgds,
Sam

Thanks for your help guys, it was a simple fix.
All I had to do was add spaces to the column name, as so [Document Part Number]

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.