Database record search Visual Basic 2010

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • alexrubio
    New Member
    • Feb 2015
    • 50

    Database record search Visual Basic 2010

    I'm new to programming and got stuck with an issue and was wondering if you could lend a hand. I have an Access database I'm building a front end for in VB 2010, I was able to connect to the database to retrieve records. I built a search feature and was able to find records with it, but I have searched and searched the web and can't find the right way to accomplish my goal. On the search I need to only search records that are marked "Active" as per the "Active" checkbox, I have tried all possible combinations and I cannot get it to work, here is my code:

    Code:
     Dim searchString As String = txtAssetTagSearch.Text
            Dim dataRow() As DataRow = AMSDataSet.tblITEquipment.Select("AssetTag like '%" & searchString & "%'", "AssetTag")
            If dataRow.GetUpperBound(0) >= 0 Then
                Dim index As Integer
                index = TblITEquipmentBindingSource.Find("AssetTag", dataRow(0).Item("AssetTag").ToString)
                TblITEquipmentBindingSource.Position = index
    
            Else
    
                MsgBox("Record NOT Found!", MsgBoxStyle.Exclamation, "Asset Tag Search")
                txtAssetTagSearch.Text = ""
    
            End If
    I have a textbox, txtAssetTagSear ch to put the search string and a search button. He above code works fine, but I need to somehow add the respective code so that it only searches records whose "Active.che cked = True" checkbox and if not found, to return record not found.

    ANY help would be GREATLY appreciated, THANKS in advance!
    Last edited by alexrubio; Mar 27 '17, 12:52 PM. Reason: misspelled word.
  • alexrubio
    New Member
    • Feb 2015
    • 50

    #2
    Anyone have any ideas on this? Going crazy here, lol...

    Comment

    • Luk3r
      Contributor
      • Jan 2014
      • 300

      #3
      Since no one has answered I will give you my best opinion. Since it's Access-related, I'm not super fluent, but here it goes. I would think you would add an additional query line that includes whether the record is active or not. Something like this, but again, the syntax is likely incorrect:
      Code:
      Dim dataRow() As DataRow = AMSDataSet.tblITEquipment.Select("AssetTag like '%" & searchString & "%' and Active = 1", "AssetTag")
      You would also add an If..Else statement in your code which runs the proper select statement, depending on if your Active checkbox is checked or not.

      Code:
      If Active.Checked = True Then
      	Dim dataRow() As DataRow = AMSDataSet.tblITEquipment.Select("AssetTag like '%" & searchString & "%' and Active = 1", "AssetTag")
      Else
      	Dim dataRow() As DataRow = AMSDataSet.tblITEquipment.Select("AssetTag like '%" & searchString & "%'", "AssetTag")
      End If

      Comment

      • alexrubio
        New Member
        • Feb 2015
        • 50

        #4
        Thank you so much Luk3r, that did it, I have tried that command in all parts of that line in different ways, I guess I did not try THAT one, thanks again for your help. I'm sure I'll have other questions as I continue with the project, but this is great help, thanks again!

        Comment

        Working...