pull individual data element from a datasource? how to?

S

simon

Hello
in my codebehind for a user preference form, i instantiate a new
class, and then call a function in that class. the function calls a
proc which returns a dataset (in this case a single row from the
database with some stored user preferences). this is all done in the
"Not Page.IsPostBack" IF block, so that is only runs the first time a
page is loaded.

what i'm trying to figure out is how to reference individual data
elements from the returned dataset and then pre-populate the form for
the user (meaning they have already stored their choices)

so what i have in codebehind.vb....

Dim myClass As New DBclass

Dim userPrefs As DataSet =
DBclass.GetUserDraftPrefs(Session("groupID"), Session("UserID"))

Dim userPrefCount As Integer = userPrefs.Tables(0).Rows.Count()

If userPrefCount > 0 Then
here is would want to say something like:
ddl1.selectedvalue = "the value pulled from the dataset for saved
dropdownlist1"
and so on for the other form elements
End If

i'm guessing this is pretty straight forward.
don't know the statement/syntax yet though. is it like an array where
each "column" in the dataset would be accessed by an index?

thanks for any insight/code-sample !!
 
G

Guest

simon,

You could process the single row in the table various ways.

One way:

Dim dr As DataRow = myDataset.Tables(0).Rows(0)

Now, assuming you have a column named "ID" and it is the first column in the
row, you could refer to it like this:

dr("ID")

or like this:

dr(0)

Kerry Moorman
 
S

simon

thank you kerry, i believe that is what i'm looking for. going to try
it out tonight!
out of curiousity, what would another way be to do it? learning the
language, so i appreciate any and all tips! take care
 

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

Top