datreader question

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a sub that is ran to populate a ComboBox from a database. The code
runs fine except that it doesn't show the first result of the query. What am
I not doing right? The Sub is below.

Thanks for your help
Mike


'Sub
Private Sub GetWeightKitData(ByVal weightClass As String)
'Query the db using the balance data to get the balance Id number
Dim wkSQL As String

'Select BalanceId fo display on the form
wkSQL = "Select Weight_Kit from Tab_Weight_Kit_Details Where
(Balance_Class = '" & weightClass & "') order by Weight_Kit Asc"

'MessageBox.Show(wkSQL)

Me.OraComm.CommandType = CommandType.Text
Me.OraComm.CommandText = wkSQL

Me.OraConn.Open()

Dim drwk As OracleDataReader = OraComm.ExecuteReader()
drwk.Read()

While drwk.Read()
cmbWeightKits1.Items.Add(drwk.Item(0))
cmbWeightKits2.Items.Add(drwk.Item(0))
End While

Me.OraConn.Close()

End Sub
 
Mike,

Why do you not simple use a datatable, that fits the nicest with a combobox.

Cor
 
I am new to this so there may be a better way. I use the database because
the table will be changing fairly frequently. Would a datatable be
"hardcoded" or is there something else?

Thanks for your reply
Mike
 
Also, I am not sure if it is a combo box proplem

If I
While drwk.Read() ' VB.NET
MessageBox.Show((drwk.Item(0))
cmbWeightKits2.Items.Add(drwk.Item(0))
End While

My messagebox shows all but the first value too. There must be something
wron with my loop maybe??

Thanks again
Mike
 
You are calling Read on the datareader right before the while loop begins.
Thus, you call it twice in the beginning, starting off at the second row
instead of at the first.
 
Back
Top