473,379 Members | 1,539 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

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:

Expand|Select|Wrap|Line Numbers
  1.  Dim searchString As String = txtAssetTagSearch.Text
  2.         Dim dataRow() As DataRow = AMSDataSet.tblITEquipment.Select("AssetTag like '%" & searchString & "%'", "AssetTag")
  3.         If dataRow.GetUpperBound(0) >= 0 Then
  4.             Dim index As Integer
  5.             index = TblITEquipmentBindingSource.Find("AssetTag", dataRow(0).Item("AssetTag").ToString)
  6.             TblITEquipmentBindingSource.Position = index
  7.  
  8.         Else
  9.  
  10.             MsgBox("Record NOT Found!", MsgBoxStyle.Exclamation, "Asset Tag Search")
  11.             txtAssetTagSearch.Text = ""
  12.  
  13.         End If
I have a textbox, txtAssetTagSearch 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.checked = True" checkbox and if not found, to return record not found.

ANY help would be GREATLY appreciated, THANKS in advance!
Mar 24 '17 #1

✓ answered by Luk3r

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:
Expand|Select|Wrap|Line Numbers
  1. 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.

Expand|Select|Wrap|Line Numbers
  1. If Active.Checked = True Then
  2.     Dim dataRow() As DataRow = AMSDataSet.tblITEquipment.Select("AssetTag like '%" & searchString & "%' and Active = 1", "AssetTag")
  3. Else
  4.     Dim dataRow() As DataRow = AMSDataSet.tblITEquipment.Select("AssetTag like '%" & searchString & "%'", "AssetTag")
  5. End If

3 1743
Anyone have any ideas on this? Going crazy here, lol...
Mar 30 '17 #2
Luk3r
300 256MB
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:
Expand|Select|Wrap|Line Numbers
  1. 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.

Expand|Select|Wrap|Line Numbers
  1. If Active.Checked = True Then
  2.     Dim dataRow() As DataRow = AMSDataSet.tblITEquipment.Select("AssetTag like '%" & searchString & "%' and Active = 1", "AssetTag")
  3. Else
  4.     Dim dataRow() As DataRow = AMSDataSet.tblITEquipment.Select("AssetTag like '%" & searchString & "%'", "AssetTag")
  5. End If
Mar 30 '17 #3
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!
Mar 30 '17 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Eglute | last post by:
Hello I want to show the results of database query in Visual basic. Do you know how to do this? I want to show the results in objects such as label or text box. Please help me. My code is: Dim db...
1
by: Eglute | last post by:
Hello I want to show the results of MS Access database query in Visual basic. Do you know how to do this? I want to show the results in objects such as label or text box. Please help me. My code is:...
4
by: chowdhury | last post by:
Hi, I am new in visual basic. i want to know how to connect and access data to MS Access or MS SQL database from a visual basic form.plz write me the code. Regards, chowdhury
2
by: sandipdeshmukh | last post by:
how to connect both MS Access and MS SQL database in one visual basic form
2
by: Chandrajit | last post by:
Hi How we can take run time database back using Visual Basic 6.0. For SQL Server and Access database.
1
by: murlikrishna | last post by:
i was created an application in visual basic 2010 .but need to make my application to automatically run at windows start up.i know in vb6.0 but i dont know in vb2010 i got an idea to copy the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.