Add parameters to a SelectCommand statement in DataAdapter

rvermeulen

Member
Joined
Apr 2, 2003
Messages
17
Location
New Jersey
I thought this was fairly straight forward, but Im having difficulty getting my DataAdapter to accept the values of my parameters. Ive created a connection and DataAdapter from the design window, and configured my DataAdapter through the QueryBuilder. In the QueryBuilder, I added 4 where criteria, such as "LIKE @city".

From my understanding, Ive created 4 parameters that I can pass to the SelectCommand to help qualify the records to be loaded into the dataset.

Ive verified that the Parameter value is what the user has entered from the WebForm, Im just not sure why the DataAdapter is not populating the parameter value into the SelectCommand. Ive appended the % sign to each parameter since each one is using a LIKE statement in the sql statement.

Here is my code:
If txtGroupNumber.Text.Trim <> "" Then
daGroup.SelectCommand.Parameters.Add("@groupnumber", txtGroupNumber.Text.Trim.ToString & "%")
Else
daGroup.SelectCommand.Parameters.Add("@groupnumber", "%")
End If

If txtGroupName.Text.Trim <> "" Then
daGroup.SelectCommand.Parameters.Add("@groupname", txtGroupName.Text.Trim.ToString & "%")
Else
daGroup.SelectCommand.Parameters.Add("@groupname", "%")
End If

If txtAddress.Text.Trim <> "" Then
daGroup.SelectCommand.Parameters.Add("@address1", txtAddress.Text.Trim.ToString & "%")
Else
daGroup.SelectCommand.Parameters.Add("@address1", "%")
End If

If txtCity.Text.Trim <> "" Then
daGroup.SelectCommand.Parameters.Add("@city", txtCity.Text.Trim.ToString & "%")
Else
daGroup.SelectCommand.Parameters.Add("@city", "%")
End If

OleDbConn.Open()

daGroup.Fill(DsGroupList1, "group")
dgGroupList.DataBind()

Please someone help me

Thanks in advance.
Rick
 
Back
Top