seano
Active member
- Joined
- Jul 4, 2012
- Messages
- 32
- Programming Experience
- Beginner
Hi i am trying to run a like query to an access database from vb.net the problem is it doesn't return any data i have tryed using both '*' and '%' as the wild cards the '*' works in access query but not when ran from vb.net through an OLEDB connection
Feild is getting a value from a combobox which holds the column names they wish to search in and txtsearch.text is what they are searching for.
here is the whole function:
there is also two radio buttons that check what wild card is to be used 'start of feild' or 'anywhere in feild', i know the solution is probably an easy one as i am not have to much success with querys lately lol,
thanks for your time,
VB.NET:
Dim DAPT As New OleDbDataAdapter("SELECT * FROM CatalistT WHERE [" & Feild & "] = '" & txtsearch.Text & "*'", DCON)
VB.NET:
Dim DAPT As New OleDbDataAdapter("SELECT * FROM CatalistT WHERE [" & Feild & "] = '" & txtsearch.Text & "%'", DCON)
Feild is getting a value from a combobox which holds the column names they wish to search in and txtsearch.text is what they are searching for.
here is the whole function:
VB.NET:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsearch.Click
Call SelectQuery(cbfeilds.Text)
End Sub
Private Sub SelectQuery(ByVal Feild As String)
Dim DSObject As New DataSet
Dim DCON As OleDbConnection
'create and open the data connection
DCON = New OleDbConnection(connectionstring)
Try
DCON.Open()
If rbStart.Checked Then
'Run select query with start of feild wildcards
' Data Adaptor with connection to show all from table ^
Dim DAPT As New OleDbDataAdapter("SELECT * FROM CatalistT WHERE [" & Feild & "] = '" & txtsearch.Text & "*'", DCON)
'Put everything from Data Adapter into DATA SET
DAPT.Fill(DSObject, "CatalistT")
MsgBox(DSObject.Tables(0).Rows.Count)
DGVPartlist.DataSource = DSObject
DGVPartlist.DataMember = DSObject.Tables(0).TableName
Else
'Run select query with anywhere in feild wildcards
' Data Adaptor with connection to show all from table ^
Dim DAPT As New OleDbDataAdapter("SELECT * FROM CatalistT WHERE " & Feild & " = '*" & txtsearch.Text & "*'", DCON)
'Put everything from Data Adapter into DATA SET
DAPT.Fill(DSObject, "CatalistT")
DGVPartlist.DataSource = DSObject
DGVPartlist.DataMember = DSObject.Tables(0).TableName
End If
Catch ex As Exception
MsgBox("Error Opening {0} " & DCON.DataSource & " Error " & ex.ToString, MsgBoxStyle.Critical, "Look It Up!")
Console.WriteLine("Error Opening {0}", DCON.DataSource)
Finally
'close connection
DCON.Close()
End Try
there is also two radio buttons that check what wild card is to be used 'start of feild' or 'anywhere in feild', i know the solution is probably an easy one as i am not have to much success with querys lately lol,
thanks for your time,
Last edited: