|
-
March 17th, 2003, 01:57 PM
#1
can I pass an SQL query result into a string.
I want to display first and last names quieried from a database as textFileds or lables is this possible and how.
-
March 17th, 2003, 05:05 PM
#2
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.
-
March 17th, 2003, 05:54 PM
#3
-
March 21st, 2003, 01:34 PM
#4
Re my problem
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
-
March 21st, 2003, 02:03 PM
#5
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.
-
March 24th, 2003, 05:57 AM
#6
Please tell me how to itterate though the data table.
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
-
March 24th, 2003, 05:55 PM
#7
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|