CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Mar 2003
    Location
    Cardiff and Oxford
    Posts
    44

    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.

  2. #2
    Join Date
    Feb 2003
    Posts
    51
    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.

  3. #3
    Join Date
    Mar 2003
    Posts
    15
    Hi

    You want in VB or ASP

  4. #4
    Join Date
    Mar 2003
    Location
    Cardiff and Oxford
    Posts
    44

    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

  5. #5
    Join Date
    Feb 2003
    Posts
    51
    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.

  6. #6
    Join Date
    Mar 2003
    Location
    Cardiff and Oxford
    Posts
    44

    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


  7. #7
    Join Date
    Feb 2003
    Posts
    51
    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
  •  





Click Here to Expand Forum to Full Width

Featured