title: Search through the database using a combobox, if an item is in a database, prompt will appear
body: <p>Good day everyone.</p>
  
  <p>I'm making a POS and Inventory Management System and I'm having a problem with this particular module as of now.</p>
  
  <p>When adding an item to purchase order list, if an item is already in the purchaseorder database, the system will prompt that there is already a pending order. I've done the prompt, but the adding to the database was kinda messed up. It doesn't do a thing at all. The code there is working when I remove the ds.hasrows and while dr.read conditions. This is my code:</p>
  
  <pre><code>Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
  
      Ceiling = CInt(txtCeiling.Text)
      TotalQuantity = CurrentItemQuantity + CInt(txtPurchaseQty.Text)
  
      If TotalQuantity &gt; Ceiling Then
          MsgBox("Exceeds Ceiling Point.")
      Else
  
          sqlString = "SELECT PRODUCT_ID FROM posinventory.purchaseorder WHERE purchaseorder.PRODUCT_ID = '" &amp; cboProductID.Text &amp; "'"
  
          cmd = New MySqlCommand(sqlString, con)
          dr = cmd.ExecuteReader
  
          If dr.HasRows Then
              While dr.Read
  
                  If CurrentItem = dr.Item("PRODUCT_ID") Then
  
                      MsgBox("Product has pending order.")
                      cboProductID.Focus()
  
                  Else
  
                      sqlString = "INSERT INTO posinventory.purchaseorder (PRODUCT_ID, PURCHASE_QUANTITY, DATE_PURCHASED, TIME_PURCHASED) VALUES (" &amp; cboProductID.Text &amp; ", '" &amp; txtPurchaseQty.Text &amp; "', '" &amp; txtDate.Text &amp; "', '" &amp; txtTime.Text &amp; "')"
  
                      Try
                          cmd = New MySqlCommand(sqlString, con)
                          dr = cmd.ExecuteReader
                          dr.Close()
                      Catch ex As Exception
                          MsgBox("Error saving to database. Error is: " &amp; ex.Message)
                          Exit Sub
                      End Try
  
                      MsgBox("Transaction Complete.")
  
                      lvOrderList.Items.Clear()
  
                      sqlString = "SELECT posinventory.purchaseorder.TRANSACTION_ID, posinventory.products.PRODUCT_ID, posinventory.products.PRODUCT_NAME, posinventory.products.SUPPLIER_NAME, posinventory.purchaseorder.PURCHASE_QUANTITY, posinventory.purchaseorder.DATE_PURCHASED, posinventory.purchaseorder.TIME_PURCHASED FROM posinventory.purchaseorder, posinventory.products WHERE posinventory.purchaseorder.PRODUCT_ID = posinventory.products.PRODUCT_ID"
                      cmd = New MySqlCommand(sqlString, con)
                      da = New MySqlDataAdapter(cmd)
                      ds = New DataSet
                      da.Fill(ds, "Table")
  
                      Dim i As Integer = 0
                      Dim j As Integer = 0
  
                      For i = 0 To ds.Tables(0).Rows.Count - 1
                          For j = 0 To ds.Tables(0).Columns.Count - 1
                              itemcol(j) = ds.Tables(0).Rows(i)(j).ToString()
                          Next
  
                          Dim lvi As New ListViewItem(itemcol)
                          Me.lvOrderList.Items.Add(lvi)
                      Next
  
                      grpCreateOrder.Enabled = False
                      grpOrderList.Enabled = True
                      cboProductID.SelectedIndex = -1
                      txtPurchaseQty.Text = ""
                      txtDate.Text = ""
                      txtTime.Text = ""
                      txtProductName.Text = ""
                      txtSupplier.Text = ""
                      txtQty.Text = ""
                      txtCeiling.Text = ""
                      btnBack.Enabled = True
  
                  End If
  
              End While
  
          End If
  
          dr.Close()
  
      End If
  
  End Sub
  </code></pre>