954,557 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Runtime error ms access "No value given for one or more required parameters"

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
Newbie Poster
20 posts since May 2010
Reputation Points: 10
Solved Threads: 0
 

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

Phasma
Junior Poster in Training
81 posts since Nov 2008
Reputation Points: 21
Solved Threads: 21
 

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(,)

Rgds,
Sam

samson_zed
Newbie Poster
24 posts since Sep 2007
Reputation Points: 13
Solved Threads: 6
 

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]

dakaboguy
Newbie Poster
20 posts since May 2010
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: