Saturday, March 24, 2012

Passing a "where" claus to populate a datagrid on another form.

I have a form where a user can enter mulitple search criteria. Depending upon what they choose I begin stringing the information into a string field that I pass to another form.

It is my intention to open this form that contains a datagrid which returns the records that match their search criteria.

I have had success sending the information, but I am completely lost as to how I use this information.

I dragged the dbconnection, the dataadapter and created the dataset onto the form, but I am not sure if this is how I should have done it. Perhaps all of this should be done in code and create the select string in code for the dataadapter? Does anyone have code that they could share the accomplishes this?

Currently the form brings up all records, (before I started tinkering), but I do not know how to set the 'where' claus.

Thanks for your helpHere is some of the code I am working with:

Dim conn As New OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=c:\Access_ResourceDB\Access_ResourceDb_Backend\ResourceDb_be.mdb")

Dim ds As New DataSet("MyDataSet")

Dim objCmd As New OleDbDataAdapter("Select RecId,Name,Age,Town,HowmPhone,Email FROM tblContacts " & "Where " & pasRecCrit & ";", conn)

conn.Open()
objCmd.Fill(ds, "MyDataSet")
Me.DataGrid1.DataSource = ds.Tables("MyDataSet")
Me.DataGrid1.DataBind()

This is just one of the ways I have tried. Right now I get an error stating that
"No value given for one or more required parameters", on the objCmd.fill line.
Thanks
What do have in the pasRecCrit variable? This looks like it should work. Maybe your Where clause isn't formatted correctly.

0 comments:

Post a Comment