Less Than Dot is a community of passionate IT professionals and enthusiasts dedicated to sharing technical knowledge, experience, and assistance. Inside you will find reference materials, interesting technical discussions, and expert tips and commentary. Once you register for an account you will have immediate access to the forums and all past articles and commentaries.
ASP.NET: Loop through data in a DataTable
From Wiki
Summary: An example that uses the Northwind Database to loop through data using a DataTable
- ' Declarations
- Dim MyConnection As System.Data.SQLClient.SqlConnection
- Dim MyDataAdapter As SqlClient.SqlDataAdapter
- Dim MyDataTable As New DataTable
- Dim MyDataRow As DataRow
- Dim strSQL As String = "SELECT ProductName FROM products"
- ' Connect and fill the DataTable
- MyConnection = New System.Data.SQLClient.SqlConnection("server=127.0.0.1; initial catalog=Northwind;uid=USERNAME;pwd=PASSWORD")
- MyConnection.Open()
- MyDataAdapter = New SqlClient.SqlDataAdapter(strSQL, MyConnection)
- MyDataAdapter.Fill(MyDataTable)
- ' Loop through DataTable
- For Each MyDataRow In MyDataTable.Rows
- Response.Write(MyDataRow.Item("ProductName"))
- Next
This Hack is part of the ASP.NET Hacks collection



LTD Social Sitings
Note: Watch for social icons on posts by your favorite authors to follow their postings on these and other social sites.