Question HELLP! No value given for one or more required parameters.

mpau23

Member
Joined
Dec 13, 2009
Messages
12
Programming Experience
1-3
Hi, im getting an error in my select statement when trying to search for records where the criteria is not the primary key, in theory, is it not just a normal select statement?

VB.NET:
cmbCriteria.Text = "FirstName"
txtSearch.Text = "Bob"

Dim dacustomersearch As New OleDb.OleDbDataAdapter("SELECT * FROM tblCustomer WHERE " & cmbCriteria.Text & " = " & txtSearch.Text & " ", connectstring)


Dim dscustomersearch As New DataSet
dacustomersearch.Fill(dscustomersearch, "tblResult")

        For rownum = 0 To dscustomersearch.Tables("tblResult").Rows.Count - 1
            Dim customerid As String = dscustomersearch.Tables("tblResult").Rows(rownum).Item("CustomerID").ToString()
            Dim firstname As String = dscustomersearch.Tables("tblResult").Rows(rownum).Item("FirstName").ToString()
            Dim secondname As String = dscustomersearch.Tables("tblResult").Rows(rownum).Item("SecondName").ToString()
            Dim HomeNumber As String = dscustomersearch.Tables("tblResult").Rows(rownum).Item("HomeNumber").ToString()
            Dim MobileNumber As String = dscustomersearch.Tables("tblResult").Rows(rownum).Item("MobileNumber").ToString()
            Dim AddressLine1 As String = dscustomersearch.Tables("tblResult").Rows(rownum).Item("AddressLine1").ToString()
            Dim AddressLine2 As String = dscustomersearch.Tables("tblResult").Rows(rownum).Item("AddressLine2").ToString()
            Dim County As String = dscustomersearch.Tables("tblResult").Rows(rownum).Item("County").ToString()
            Dim Postcode As String = dscustomersearch.Tables("tblResult").Rows(rownum).Item("Postcode").ToString()
            Dim EmailAddress As String = dscustomersearch.Tables("tblResult").Rows(rownum).Item("EmailAddress").ToString()

Thanks in advance
 
You are correct, it is just a 'normal' select statement. However, it is correctly throwing an error because it is treating Bob as a unsupplied parameter, rather than a string, because you didnt wrap it in quotes.

If you had written it using parameters, it would have been fine :D See the link in my signature.
 
Thanks for your quick response,

However, when use the value
cmbCriteria.Text = customerid
txtSearch.Text = "135"

it shows no errors?

Thanks again
 
Yes - CustomerID is (I assume) an integer field, and therefore the 135 doesnt need to be wrapped in quotes. This is why you should change to parameters, as it removes ALL this uncertainty.
 
So how would i define the peramiter? and how would i quote the textbox? Sorry, ive been reading your thread in your link but im still confused. could you give me an example?
 
Back
Top