Selecting a single record from a dataset...help a newbie

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I've got a dataset loaded on my page that contains about 150 records. there
are no controls right now to display this data. This page only has a textbox
and a submit button. I'd like to have the user enter a record number, and
upon clicking Submit, the record will display on this same page.

I know i'm going to use Webform labels to display the data, but i'm unsure
of the command to use to select the correct record out of the dataset, based
on the value in the textbox. is this something that can be done efficiently
using the postback, or should i direct to a separate page?
 
Hi D Lee:

The DataTable object inside of your DataSet has a Select method you
can use to retrieve an array of rows. If the table has a primary key
column (a column that uniquely identifies each row), you could select
based on the key, something like
DataRow[] dr = ds.Tables[0].Select("id = 5");
Then just march through the fields in dr[0] (but check to make sure
the record exists first).

The bigger question though, is why go to the trouble of pulling back
all 150 records. Why not send a query to the database that will pull
back just the one record you need?
 
If you aren't displaying the records the best thing to do rather than sift
through a DataSet would be to create a stored procedure that would pull this
record up for you upon submitting the form and then bind the values from your
new DataSet to your labels and things.

Hope this helps.
 
Back
Top