No value given for one or more required parameters. error during Search

ms-access, vb.net

Solution

I suppose that the error is in the text `asd` passed as value for the customer name

cmd = New OleDbCommand("Select * from PO_Record_Table where Customer='asd'", con)

Putting it in single quotes allows the db engine to recognize it as a string value to check against the `Customer` column name. Without quotes it is interpreted as the name of a parameter that you haven't passed to the command.

EDIT In your comment below you try to pass, as value for the Customer column, the content of a textbox but you forget to add the quotes around your textbox text value.

cmd = New OleDbCommand("Select * from PO_Record_Table where Customer='" & textbox.text & "'", con)

However, this should never be done using the string concatenation method, but always with the parameterized approach

cmd = New OleDbCommand("Select * from PO_Record_Table where Customer=@custName", con)
cmd.Parameters.AddWithValue("@custName", Txt_Find.Text)
dr = cmd.ExecuteReader
.....

This is the only good method to query a database passing a command text with values obtained by user input. This method allows your code to be safe from SQL Injection attacks and remove problems in parsing the content of the textbox. Infact, without a parameter and if your textbox contains a single quote, the string concatenation method would fail with a syntax error.

Problem

I am trying to search the data in a simple access database. The code is this ``` Call connect() con.Open() cmd = New OleDbCommand("Select * from PO_Record_Table where Customer=asd", con) dr = cmd.ExecuteReader While dr.Read MsgBox(dr(1)) End While con.Close() ``` If I press search button, the error: No value given for one or more required parameters comes on this line ``` dr = cmd.ExecuteReader ``` The record "asd" is in the database customer field as a text type. Why does this error come and how to finish this search without error?

Original source

Related problems