Question Filtering Data source code problem

Joined
Apr 15, 2013
Messages
9
Programming Experience
Beginner
Hi , i am currently designing a Inventory Management System for my school Project , the add data edit data and delete data part of the software works for me but i am kinda stuck at the filtering data part and it does not seem to work at all . This is my source Code

Sub combobox_itemID()


        Dim rs = New ADODB.Recordset


        With rs
            .Open("Select ItemID from Inventory", cn, ADODB.CursorTypeEnum.adOpenDynamic, ADODB.LockTypeEnum.adLockOptimistic)
            ComboBox1.Items.Clear()
            .MoveFirst()
            While Not .EOF
                ComboBox1.Items.Add(.Fields(0).Value)
                .MoveNext()
            End While
            ComboBox1.Text = ComboBox1.Items(0)




        End With
    End Sub
  
    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
        MessageBox.Show("Select Item ID - " & ComboBox1.Text)
        Dim lst
        Dim rs = New ADODB.Recordset
        ListView1.Items.Clear()
        With rs
            .Open("select t.ItemID,t.ItemName,t.ItemDescription,t.Quantity,t.Unit,t.Location,t.Cost,t.Status,t.DateReceived,t.Packed* from Inventory t,Warehouse s where t.ItemID=s.ItemID and s.ItemName='" & ComboBox1.Text & "'", cn, 2, 3)
            Do While Not .EOF
                lst = New ListViewItem
                lst = ListView1.Items.Add(.Fields(0).Value)
                lst.SubItems.Add(.Fields(1).Value)
                lst.SubItems.Add(.Fields(2).Value)
                lst.SubItems.Add(.Fields(3).Value)
                lst.SubItems.Add(.Fields(4).Value)
                lst.SubItems.Add(.Fields(5).Value)
                lst.SubItems.Add(.Fields(6).Value)
                lst.SubItems.Add(.Fields(7).Value)
                lst.SubItems.Add(.Fields(8).Value)
                lst.SubItems.Add(.Fields(9).Value)




                .MoveNext()
            Loop




        End With
    End Sub 


P.s I am really new to programming , i just started learning the language 4 weeks ago , sometimes i might not know what i am coding
 
i change it to t.itemID and for that particular part and it still cant work
That doesn't answer either of my questions. Show us your code and tell us what happens when you run it.
 
That doesn't answer either of my questions. Show us your code and tell us what happens when you run it.


Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
MessageBox.Show("Select Item ID - " & ComboBox1.Text)
Dim lst
Dim rs = New ADODB.Recordset
ListView1.Items.Clear()
With rs
.Open("select t.ItemID,t.ItemName,t.ItemDescription,t.Quantity,t.Unit,t.Location,t.Cost,t.Status,t.DateReceived,t.Packed* from Inventory t,Warehouse s where t.ItemID=s.ItemID and t.ItemID=" & ComboBox1.Text & "'", cn, 2, 3)
Do While Not .EOF
lst = New ListViewItem
lst = ListView1.Items.Add(.Fields(0).Value)
lst.SubItems.Add(.Fields(1).Value)
lst.SubItems.Add(.Fields(2).Value)
lst.SubItems.Add(.Fields(3).Value)
lst.SubItems.Add(.Fields(4).Value)
lst.SubItems.Add(.Fields(5).Value)
lst.SubItems.Add(.Fields(6).Value)
lst.SubItems.Add(.Fields(7).Value)
lst.SubItems.Add(.Fields(8).Value)
lst.SubItems.Add(.Fields(9).Value)




.MoveNext()
Loop




End With
End Sub

The combo box can't work at all, i want it to filter the itemID in the listview. E.g. when i choose or type "2" only itemID "2" appears in the listview.
 
Four things:

1. I have asked you twice now to tell us what happened when you ran that code and still haven't done so. If you want our help then please provide the information we ask for when we ask for it, because we're asking for it for a reason. Don't just keep saying "it doesn't work" over and over. Tell us explicitly what you expect to happen and what actually happens.

2. It took two goes to actually get your current code out of you and this shows exactly why I asked for it in the first place. I can see straight away what the issue is. Don't just tell us what you think you have done because if you had done it right then it would work. If we can't see what you've done then we can't see what's wrong with it. You shouldn't need to be prompted to provide relevant code.

3. This is a perfect example of not looking at your data and just assuming it is what you think it is. You are constructing a SQL string in code there but you have apparently not actually looked at that string to make sure that it is what you think it is. If you had then you would probably have seen the issue. It's as simple as putting this line in there:
VB.NET:
MessageBox.Show("select t.ItemID,t.ItemName,t.ItemDescription,t.Quantity,t .Unit,t.Location,t.Cost,t.Status,t.DateReceived,t. Packed* from Inventory t,Warehouse s where t.ItemID=s.ItemID and t.ItemID=" & ComboBox1.Text & "'")
4. This a perfect example of why you should use parameters to insert values into SQL code rather then string concatenation. It can't save you from all mistakes but it can save you from this one. The Blog link in my signature includes a post about Parameters In ADO.NET but you'd have to be using ADO.NET for that to be completely relevant. You can still use parameters in ADO but the details are different.
 
Back
Top