How to iterate through rows of a query?

L

Lacka

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
 
K

Karl Seguin

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top