Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to query Access database

Status
Not open for further replies.

chris86t

Technical User
Jun 13, 2008
41
US
I am using vb.net 2010 express to query an Access database. I understand how to query 1 item at a time.

My users may need to add additional filters to the query.

How would I query where 2 or more items are found.


Here is the code I now use for individual querries.

Code:
cmd = New OleDbCommand("select * from inventory where serial like '" & TextBox2.Text & "'", cn)
Code:
cmd = New OleDbCommand("select * from inventory where sku like '" & TextBox1.Text & "'", cn)
 


hi,
Code:
dim sSQL as string

sSQL =        "select * "
sSQL = sSQL & "from inventory "
sSQL = sSQL & "where serial like '*" & TextBox2.Text & "*'"
sSQL = sSQL & "  and sku    like '*" & TextBox1.Text & "*'"

cmd = New OleDbCommand(sSQL, cn)

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 

I would modify Skip's statement a little:
Code:
dim sSQL as string

sSQL =        "select * "
sSQL = sSQL & "from inventory "
sSQL = sSQL & "where [blue]1 = 1 [/blue]"
[blue]
If Len(Trim(TextBox2.Text)) > 0 Then[/blue]
  sSQL = sSQL & " and serial like '*" & TextBox2.Text & "*'"[blue]
End If
If Len(Trim(TextBox1.Text)) > 0 Then[/blue]
  sSQL = sSQL & " and sku like '*" & TextBox1.Text & "*'"[blue]
End If[/blue]

cmd = New OleDbCommand(sSQL, cn)
[tt]
Len(Trim(...[/tt] is an old VB6 syntax, I am sure VB.NET has something better :)

Have fun.

---- Andy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top