| Platform: | Visual Basic |
| Task: | Create and loop through a datareader |
| Discussion: | Create and loop through a datareader |
| Example: | Dim MySqlConnection As New SqlConnection("Data Source=" & SqlServer & ";Initial Catalog=" & DB & ";Trusted_Connection=True;")
MySqlConnection.Open()
Dim CaribouSqlCommand As SqlCommand = New SqlCommand("SELECT Distinct CaribouID FROM CaribouLocations ORDER BY CaribouID", MySqlConnection)
Dim CaribouDataReader As SqlDataReader = CaribouSqlCommand.ExecuteReader
Do While CaribouDataReader.Read()
OutputRichTextBox.AppendText(CaribouDataReader.GetValue(0) & vbNewLine)
Loop
MySqlConnection.Close() |