scottie_uk
March 17th, 2003, 12:57 PM
I want to display first and last names quieried from a database as textFileds or lables is this possible and how.:confused:
|
Click to See Complete Forum and Search --> : can I pass an SQL query result into a string. scottie_uk March 17th, 2003, 12:57 PM I want to display first and last names quieried from a database as textFileds or lables is this possible and how.:confused: Rube74 March 17th, 2003, 04:05 PM What you want to do is save your SQL results to a DataSet and then loop through the dataset to the record that you are looking for. Once you're there, you can set the label's or textbox's Text property to the column of your choosing. Probably the best place for you to start is by reading up on DataAdapters and DataSets. satscom March 17th, 2003, 04:54 PM Hi You want in VB or ASP scottie_uk March 21st, 2003, 12:34 PM I want to achive this in VB.net, I can allready get the results. I allready have the results displaying in a datagrid, how do I itterate though it and get data out, say a user name. Andrew Scott:confused: Rube74 March 21st, 2003, 01:03 PM Well, you could set up a for-next loop to loop through the records and then use an if statement to check if the current record meets the condition you're trying to connect it with. I think I heard that there might be a Search method as well, so you might want to look into that. scottie_uk March 24th, 2003, 04:57 AM I would love then to know how I can itterate though a data table and pull individual column(s) or cells out to compare or use them. Andrew.scott :confused: :confused: Rube74 March 24th, 2003, 04:55 PM Well, unless you add new tables to the dataset that you've created, you should only have one "table" in there. So, first you should figure out how many records are in the table. Assuming that the name of the dataset is ds and that there is only one table in the dataset, you could this this code to determine how many records are in the dataset: ds.Tables(0).Rows.Count This will give you a row count of the first table in the dataset ds. As you can see, since the dataset is set up like a mulit-dimensional array, each of the arrays will start with an index value of zero. This will be the upper bound of the for-next loop you'll use to iterate through the record. Then you can go through the dataset row by row and do comparisons on the columns you want. To do this you use counter to signify the index for the row and pass the name of the column in question to the Item property of the Rows property to pull out that value. For example, if you have a dataset (called ds) with only one table and are looking to pull out the value for a column called LastName when an ID is equal to 10, you would put in code like this. Dim ds As New DataSet() Dim counter As Integer = 0 Dim lastName As String = "" For counter = 0 To ds.Tables(0).Rows.Count If (ds.Tables(0).Rows(counter).Item("ID") = 10) Then lastName = ds.Tables(0).Rows(counter).Item("LastName") End If Next codeguru.com
Copyright Internet.com Inc., All Rights Reserved. |