Subject: SQL LIKE Multiple Conditions
Posted By: takwirira Post Date: 4/16/2008 5:24:10 AM
Im having some trouble using the SQL Like command with multiple conditions

where as the first line of code works with one condition the second one doesnt even thought it doesnt return any errors

Dim da As OleDbDataAdapter = New OleDbDataAdapter("SELECT * FROM chdetails WHERE chname LIKE '%" & txtFRname.Text & "%'", myConnection)

Dim da As OleDbDataAdapter = New OleDbDataAdapter("SELECT * FROM chdetails WHERE (chname LIKE '%" & txtFRname.Text & "%') AND (chsurname LIKE '%" & txtFRsname.Text & "%') AND (chDOB = '%" & txtFRdob.Text & "%')", myConnection)


Full Code is below

        Dim connString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data source =" & Server.MapPath("db2.mdb")
        Dim myConnection As OleDbConnection = New OleDbConnection
        myConnection.ConnectionString = connString
        ' create a data adapter

        Dim da As OleDbDataAdapter = New OleDbDataAdapter("SELECT * FROM chdetails WHERE (chname LIKE '%" & txtFRname.Text & "%') AND (chsurname LIKE '%" & txtFRsname.Text & "%') AND (chDOB = '%" & txtFRdob.Text & "%')", myConnection)

        ' create a new dataset

        Dim ds As DataSet = New DataSet
        ' fill dataset

        da.Fill(ds, "chdetails")
        ' Attach DataSet to DataGrid

        GridView1.DataSource = ds
        GridView1.DataBind()

        MultiView1.SetActiveView(child)

Where am I going wrong

Reply By: takwirira Reply Date: 4/16/2008 6:24:24 AM
I found it !

Dim da As OleDbDataAdapter = New OleDbDataAdapter("SELECT * FROM chdetails WHERE (chname LIKE '%" & txtFRname.Text & "%') AND (chsurname LIKE '%" & txtFRsname.Text & "%') AND (chDOB = '" & txtFRdob.Text & "')", myConnection)


instead of


Dim da As OleDbDataAdapter = New OleDbDataAdapter("SELECT * FROM chdetails WHERE (chname = '" & txtFRname.Text & "') AND (chsurname = '" & txtFRsname.Text & "') AND (chDOB = '" & txtFRdob.Text & "')", myConnection)


look very closely


Go to topic 70631

Return to index page 1