help!!
I'm a VB noob so please bear with me. I'm trying to code a Do While statement that loops through the OleDbDataReader object. Within the Do While statement, I have to build a string composed of the fields returned by the SELECT statement. The fields are as follows: ProductName, Price, InStock, Color, and Manufacturer. All the fields in the table are of the String data type. For example, the following code concatenates the ProductName fields onto a string named srtOutput:
strOutput &= objOleDbDataReader.Item("ProductName")
Attached is a doc (sorry about the quality, i had to bump it way down to fit) of the db and what the output should look like. My code is below.
Anyways if any one can help or give me an example on how to write that Do While statement I'd greatly appreciate it.
Thanks.
I'm a VB noob so please bear with me. I'm trying to code a Do While statement that loops through the OleDbDataReader object. Within the Do While statement, I have to build a string composed of the fields returned by the SELECT statement. The fields are as follows: ProductName, Price, InStock, Color, and Manufacturer. All the fields in the table are of the String data type. For example, the following code concatenates the ProductName fields onto a string named srtOutput:
strOutput &= objOleDbDataReader.Item("ProductName")
Attached is a doc (sorry about the quality, i had to bump it way down to fit) of the db and what the output should look like. My code is below.
Anyways if any one can help or give me an example on how to write that Do While statement I'd greatly appreciate it.
Thanks.
VB.NET:
Private Const gstrConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=ProductList.mdb"
Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click
Dim objConnection As OleDbConnection
Dim objDataReader As OleDbDataReader
Dim objCommand As OleDbCommand
Dim stroutput As String
If cmbColor.Text = String.Empty Then
MessageBox.Show("Please select a color from the list.", "No color selected.")
End If
If cmbManufacturer.Text = String.Empty Then
MessageBox.Show("Please select a manufacturer from the list.", "No manufacturer selected.")
End If
objConnection = New OleDbConnection(gstrConnectionString)
objCommand = New OleDbCommand
objCommand.Connection = objConnection
objCommand.Connection.Open()
objCommand.CommandText = "SELECT ProductName, Price, InStock, Color, Manufacturer FROM ProductList WHERE Color LIKE '" & cmbColor.Text & "' AND Manufacturer LIKE '" & cmbManufacturer.Text & "' ORDER BY Manufacturer"
objDataReader = objCommand.ExecuteReader
While (objDataReader.Read())
MessageBox.Show("Product Name :" & objDataReader("ProductName") & ControlChars.NewLine & "Price :" & objDataReader("Price") & ControlChars.NewLine & "In Stock? :" & objDataReader("inStock"))
End While
objDataReader.Close()
End Sub
End Class
Last edited: