I am using Visual Studio 2010 and Microsoft Access 2007
I am not sure of the best way to describe my problem, but here goes
I have a query (PartsQry) in access that has 6 columns (ID, KYWD1, KYWD2, KYWD3, KYWD4, KYWD5). The KYWD columns hold various keywords that are specific to the ID.
In my application I have a textbox (SearchTxt) that a user can input up to 5 keywords, seperated by a coma. When they click the search button the application is supposed to hit the PartsQry and return only results that match all the keywords the user typed in. I think I've gotten pretty close but I'm missing something because im getting extra records.
Say the user enters the keywords "black, loud, small" and hits the search button. The QryKeyword loops through the keywords one at a time. Plugs them into the select string then delivers the records to the PartsDS table "KeywordList".
My problem is comming from my logic because im just appending the 2nd and 3rd set of records to this table. I need ONLY the records that contain all of the keywords that are typed into the search.
I dont know how much of that made sence but hopefully someone can shed some light on this problem. Ive been spinning my wheels for about 8 hours now between playing around with the code and googling.
Thanks in advance
P.S. Incase anyone is wondering. Im declaring alot of the variables like dataset/adapters globaly and referencing them from outside the class
I am not sure of the best way to describe my problem, but here goes
I have a query (PartsQry) in access that has 6 columns (ID, KYWD1, KYWD2, KYWD3, KYWD4, KYWD5). The KYWD columns hold various keywords that are specific to the ID.
In my application I have a textbox (SearchTxt) that a user can input up to 5 keywords, seperated by a coma. When they click the search button the application is supposed to hit the PartsQry and return only results that match all the keywords the user typed in. I think I've gotten pretty close but I'm missing something because im getting extra records.
VB.NET:
If KeywordRb.Checked Then
Dim Keywords() As String
Keywords = SearchTxt.Text.Split(", ")
QryKeyword(Keywords)
Try
ProductDGV.DataSource = PartsDS.Tables("KeywordList")
Catch : End Try
With ProductDGV 'The Data Grid View where i display the results
.Columns("ID").Visible = False
.Columns("KYWRD1").Visible = False
.Columns("KYWRD2").Visible = False
.Columns("KYWRD3").Visible = False
.Columns("KYWRD4").Visible = False
.Columns("KYWRD5").Visible = False
.Columns("MVTTL").Width = 190
.Columns("RELDT").Width = 65
.Columns("RTNG").Width = 85
End With
End If
Public Sub QryKeyword(ByVal Keyword() As String)
Dim SelectStr As String
Try : ProductDS.Tables("KeywordList").Clear() : Catch : End Try
For i As Integer = 0 To UBound(Keyword)
SelectStr = "SELECT [ID], " & _
"[MVTTL], " & _
"[RELDT], " & _
"[RTNG], " & _
"[KYWRD1], " & _
"[KYWRD2], " & _
"[KYWRD3], " & _
"[KYWRD4], " & _
"[KYWRD5] FROM PartsQry WHERE (" & _
"[KYWRD1] = '" & Keyword(i) & "') OR (" & _
"[KYWRD2] = '" & Keyword(i) & "') OR (" & _
"[KYWRD3] = '" & Keyword(i) & "') OR (" & _
"[KYWRD4] = '" & Keyword(i) & "') OR (" & _
"[KYWRD5] = '" & Keyword(i) & "')"
PartsDA = New OleDb.OleDbDataAdapter(SelectStr, ConStr)
Try : PartsDA.Fill(PartsDS, "KeywordList") : Catch : End Try
Next
End Sub
Say the user enters the keywords "black, loud, small" and hits the search button. The QryKeyword loops through the keywords one at a time. Plugs them into the select string then delivers the records to the PartsDS table "KeywordList".
My problem is comming from my logic because im just appending the 2nd and 3rd set of records to this table. I need ONLY the records that contain all of the keywords that are typed into the search.
I dont know how much of that made sence but hopefully someone can shed some light on this problem. Ive been spinning my wheels for about 8 hours now between playing around with the code and googling.
Thanks in advance
P.S. Incase anyone is wondering. Im declaring alot of the variables like dataset/adapters globaly and referencing them from outside the class