I have an inventory system I am making for my business. I have a form that has a listbox control that lists all the orders that have been submitted. I also have a datagrid that lists the items in the order based on what is clicked in the listbox.

I have tried the conventional dataset and filtering. I still have not managed to make this happen. The end result I am looking for is to be able to update the inventory through the datagrid as orders come in by clicking a submit button.

I appreciate any help I can get in this.

Post your code and we'll see where you went wrong.

 Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged

        Try
            Dim I As Integer
            For I = 0 To DataGridView1.Rows.Count - 1
                Dim rownum As Integer = DataGridView1.Rows.Add
                Dim conn As New SqlConnection(*******)
                Dim cmd As SqlCommand = New SqlCommand("SELECT * FROM orderstable WHERE OrderNumber = '" & ComboBox1.SelectedValue & " '", conn)
                conn.Open()
                Dim sdr As SqlDataReader = cmd.ExecuteReader()
                If (sdr.Read() = True) Then
                    Dim ordernumber As String
                    Dim orderdate As String
                    Dim itemname As String
                    Dim QuantityOrdered As String
                    Dim RepairNumber As String
                    ordernumber = sdr("ordernumber")
                    orderdate = sdr("orderdate")
                    itemname = sdr("itemname")
                    QuantityOrdered = sdr("quantity")
                    RepairNumber = sdr("RepairNumber")

                    DataGridView1.Rows.Item(rownum).Cells(0).Value = ordernumber
                    DataGridView1.Rows.Item(rownum).Cells(1).Value = orderdate
                    DataGridView1.Rows.Item(rownum).Cells(2).Value = itemname
                    DataGridView1.Rows.Item(rownum).Cells(3).Value = QuantityOrdered
                    DataGridView1.Rows.Item(rownum).Cells(5).Value = RepairNumber
                End If

            Next

        Catch ex As Exception

        End Try




    End Sub

I guess that would have helped. This is what I have so far. It does work but only returns the first record then stops. I am also trying to get it to when the user clicks on a new item from the ddl it clears out the datagrid and populates it with the new data.

I am still working on it. If I find out what I am doing wrong then I will post it on here and it just might help someone else out.

Thanks

Write the event in combobox1 selectediIndex change event...make correct connections

Try
   Dim myCommand As New SqlCommand
   With myCommand
        .CommandText = "SELECT ordernumber,orderdate,itemname,quantity,RepairNumber FROM orderstable WHERE OrderNumber = '" & ComboBox1.Text & "'"
        .CommandType = CommandType.Text
        .Connection = conn
   End With
   Dim dt As New DataTable
   dt.Load(myCommand.ExecuteReader)
   With DatagridView1
        .AutoGenerateColumns = True
        .DataSource = dt
   End With
Catch ex As Exception
   Throw ex
End Try

I've tried something simliar to that but was unable to get the code so it would populate the datagrid with the data. It doesn't populate the datagridview at all. I'm gonna keep workin' on it. lol

You are using if instead of while. If is checked once and get's done with, while on the other hand will be checked until it returns False.
So change this :

            If (sdr.Read() = True) Then
                Dim ordernumber As String
                Dim orderdate As String
                Dim itemname As String
                Dim QuantityOrdered As String
                Dim RepairNumber As String
                ordernumber = sdr("ordernumber")
                orderdate = sdr("orderdate")
                itemname = sdr("itemname")
                QuantityOrdered = sdr("quantity")
                RepairNumber = sdr("RepairNumber")
                DataGridView1.Rows.Item(rownum).Cells(0).Value = ordernumber
                DataGridView1.Rows.Item(rownum).Cells(1).Value = orderdate
                DataGridView1.Rows.Item(rownum).Cells(2).Value = itemname
                DataGridView1.Rows.Item(rownum).Cells(3).Value = QuantityOrdered
                DataGridView1.Rows.Item(rownum).Cells(5).Value = RepairNumber
            End If

to this:

                    Dim rownum As Integer
                    Dim ordernumber As String
                    Dim orderdate As String
                    Dim itemname As String
                    Dim QuantityOrdered As String
                    Dim RepairNumber As String

                 While sdr.Read() 
                     rownum = DataGridView1.Rows.Add 

                    ordernumber = sdr("ordernumber")
                    orderdate = sdr("orderdate")
                    itemname = sdr("itemname")
                    QuantityOrdered = sdr("quantity")
                    RepairNumber = sdr("RepairNumber")
                    DataGridView1.Rows.Item(rownum).Cells(0).Value = ordernumber
                    DataGridView1.Rows.Item(rownum).Cells(1).Value = orderdate
                    DataGridView1.Rows.Item(rownum).Cells(2).Value = itemname
                    DataGridView1.Rows.Item(rownum).Cells(3).Value = QuantityOrdered
                    DataGridView1.Rows.Item(rownum).Cells(5).Value = RepairNumber
                End while

Oh and you don't need to add the record before you open the con. Put it inside the while so it will only get inserted if data are found/connection succeeds/etc.

That makes a ton of sense there. And it worked perfectly. Thanks for your help!

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.