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

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?
 
S

Scott Allen

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?
 
G

Guest

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top