this is what i want to do but it seems my code doesn't do what i wanted.
when i select an item in cbo_Item i want to loop the corresponding Item_Stock into cbo_QTY where all the numbers below Item_Stock is shown in is my code...

Private Sub loop_QTY()
    Dim qty As Integer
    sqlstring = "SELECT Item_Stock from tbl_Products as '" & qty & "' WHERE Item_Name = '" & cbo_Items.Text & "' "
    Dim i As Integer

        For i = 0 To Val(qty)
            cbo_QTY.Text = i + 1

End Sub

did i miss anything..please help...

You will want to load the data into a datatable to get the corresponding information.

If the Item_Stock field holds the quantity you just need to select it and get the value from the adapter.

For example:

Dim da As New OleDBDataAdapter(New OleDBCommand("SELECT Item_Stock FROM tbl_Products AS Qty WHERE Item_Name='" & cbo_Items.Text & "'",New OleDBConnection("MyConnectionStringHere"))
Dim ds As New DataSet


If ds.Tables("Quant").Rows.Count > 0 Then MsgBox("Current count is:" & ds.Tables("Quant").Rows(0)("Qty"))
Private Sub loop_QTY()
        Dim sql As String = "SELECT Item_Qty from tbl_Products WHERE Item_Name = '" & cbo_Items.Text & "' "

        Dim cmd As New OleDbCommand(sql, con)
        Dim dr As OleDbDataReader

        dr = cmd.ExecuteReader()
        While dr.Read()
        End While
    End Sub

Hope the above code will help you.!

This article has been dead for over six months. Start a new discussion instead.