|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
pull individual data element from a datasource? how to?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 !! 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 Show quoteHide quote "simon" wrote: > 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 !! > > 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 Show quoteHide quote >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 > > >"simon" wrote: > >> 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 !! |
|||||||||||||||||||||||