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!

SQL Like command with multiple conditions

Status
Not open for further replies.

takwirira

Programmer
Mar 6, 2007
23
GB
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
 
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top