ba1959nh Level: Scholar
 Registered: 10-05-2006 Posts: 39
|
Re: used loop in sql?
I think that you can use a For - Next loop if your data is in a DataSet.
Below is a code snippet.
I hope this helps.
'Set up the keys to data access, the DataSet, Connection and Adapter.
Dim myDataSet As System.Data.DataSet
Dim myConnection As System.Data.SqlClient.SqlConnection
Dim myAdapter As System.Data.SqlClient.SqlDataAdapter
'The connection string should point to your local SQL Server
Dim connString As String = "Data Source=Gryphon;" & _
"Initial Catalog ubs;" & _
"Integrated Security=SSPI"
'Open the connection
myConnection = New SqlConnection(connString)
'The Adapter has the command in it.
myAdapter = New SqlDataAdapter("select * from Titles", myConnection)
'Fill the dataset with data using the adapter.
myDataSet = New DataSet
myAdapter.Fill(myDataSet, "Titles")
'Loop through the rows and write to the Output window.
Dim row As System.Data.DataRow
For Each row In myDataSet.Tables(0).Rows
Debug.Write(row(1).ToString)
Next
|