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 cbo_QTY...here 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 & "' "
    con.Open()
    Dim i As Integer

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

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

da.Fills(ds,"Quant")

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

        cbo_QTY.Items.Clear()
        con.Open()
        dr = cmd.ExecuteReader()
        While dr.Read()
            cbo_QTY.Items.Add(dr(0))
        End While
        con.Close()
    End Sub

Hope the above code will help you.!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.