How to iterate through rows of a query?

Discussion in 'ASP .Net' started by Lacka, Dec 31, 2004.

  1. Lacka

    Lacka Guest

    Hi,

    If I have this sequence:

    Dim dbConnection As System.Data.IDbConnection = New
    System.Data.SqlClient.SqlConnection(ConfigurationSettings.AppSettings("DB"))
    Dim dbCommand As System.Data.IDbCommand = New
    System.Data.SqlClient.SqlCommand
    Dim dataAdapter As System.Data.IDbDataAdapter = New
    System.Data.SqlClient.SqlDataAdapter
    Dim dataSet As System.Data.DataSet = New System.Data.DataSet

    dbCommand.Connection = dbConnection
    dbCommand.CommandText = "SELECT * FROM MY_TABLE"

    dataAdapter.SelectCommand = dbCommand

    dataAdapter.Fill(dataSet)

    how can I iterate through the rows of the query, like this

    <open result set>
    <while not Eof(result set)>
    <read in the current row>
    <store fields into variables>
    <do something with stored values>
    <step result set forward ("next")>
    <end while>
    <close result set>

    thanks,
    Lacka
    Lacka, Dec 31, 2004
    #1
    1. Advertising

  2. Lacka

    Karl Seguin Guest

    you mean like this:

    for each row as DataRow in dataSet.Tables(0).Rows
    dim id as integer = convert.toInt32(row("My_TableColumn1"))
    dim name as string = convert.ToString(row("My_TableColumn2"))
    ...
    next

    Karl

    --
    MY ASP.Net tutorials
    http://www.openmymind.net/


    "Lacka" <> wrote in message
    news:...
    > Hi,
    >
    > If I have this sequence:
    >
    > Dim dbConnection As System.Data.IDbConnection = New
    >

    System.Data.SqlClient.SqlConnection(ConfigurationSettings.AppSettings("DB"))
    > Dim dbCommand As System.Data.IDbCommand = New
    > System.Data.SqlClient.SqlCommand
    > Dim dataAdapter As System.Data.IDbDataAdapter = New
    > System.Data.SqlClient.SqlDataAdapter
    > Dim dataSet As System.Data.DataSet = New System.Data.DataSet
    >
    > dbCommand.Connection = dbConnection
    > dbCommand.CommandText = "SELECT * FROM MY_TABLE"
    >
    > dataAdapter.SelectCommand = dbCommand
    >
    > dataAdapter.Fill(dataSet)
    >
    > how can I iterate through the rows of the query, like this
    >
    > <open result set>
    > <while not Eof(result set)>
    > <read in the current row>
    > <store fields into variables>
    > <do something with stored values>
    > <step result set forward ("next")>
    > <end while>
    > <close result set>
    >
    > thanks,
    > Lacka
    >
    >
    Karl Seguin, Dec 31, 2004
    #2
    1. Advertising

  3. Lacka

    Lacka Guest

    Thanks!
    Lacka, Dec 31, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Gogo
    Replies:
    1
    Views:
    2,083
    Sudsy
    Sep 4, 2003
  2. runescience
    Replies:
    0
    Views:
    1,439
    runescience
    Feb 9, 2006
  3. John
    Replies:
    4
    Views:
    892
    RedGrittyBrick
    Apr 1, 2008
  4. Venkat r m Reddi

    iterate excel columns/rows

    Venkat r m Reddi, Dec 30, 2009, in forum: Ruby
    Replies:
    0
    Views:
    155
    Venkat r m Reddi
    Dec 30, 2009
  5. Iterate through table rows

    , Jun 23, 2010, in forum: Javascript
    Replies:
    5
    Views:
    100
Loading...

Share This Page