Showing posts with label criteria. Show all posts
Showing posts with label criteria. Show all posts

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.

Wednesday, March 21, 2012

Passing a parameter to another page

On one page I have a datagrid which is filled when the user selects some search criteria (e.g. surname or DoB) in different text fields and clicking on a button control.

The datagrid also contains a 'button column' which the user can use to edit and save changes to individual records to the db.

I use the following code to access the PK of the table in question as a parameter for my update query:

Dim strPatID As String = e.Item.Cells(0).Text

strSQL = "UPDATE blah "
strSQL = strSQL & "SET blah blah blah"
strSQL = strSQL & "WHERE patid = '" & strPatID & "'"

All of this works fine.

However, I also want users to be able to add records to a related table (which is at the many end of a relationship) based on the record they've selected from the datagrid. I've set up a 'hyperlink column' in the same datagrid which redirects them to another page where they'll be able to add data and save it. Fine so far.

The problem is of course, I need the patid as the foreign key to this second table. How can I pass this as a parameter to the second page? Am I doing this the right way or is there a better way to add records to related tables?

I hope I've made myself clear. Please let me know if you need additional information.

Thanks in advance for any help.

MoYou could pass it in the querystring to the new page:

DetailEntry.aspx?PatID=xxxxxx

On the second page, you can use Request.Querystring("PatID") to get the value
Thanks very much for the response Jim. I'll try it out.
Best regards to JimRoss:

In addition to using QueryString, you can also think of :

Session Variables as another solution, in addition to the other solutions.

regards