1 Replies - 4332 Views - Last Post: 13 July 2012 - 05:24 AM Rate Topic: -----

#1 maiOHmai  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 86
  • Joined: 09-July 12

Clauses

Posted 12 July 2012 - 09:56 PM

i want to search two columns consecutively(FName and LName columns). I'm using the code below:
-----------
ElseIf cmbCAT.Text = "Full Name" Then
da = New OleDbDataAdapter("Select * from list where (FName = '" & txtSearch.Text & "', LName = '" & txtSearch.Text & "')", con)
------------
but it is not working. what's wrong with my code?

Is This A Good Question/Topic? 0
  • +

Replies To: Clauses

#2 rgfirefly24  Icon User is offline

  • D.I.C Lover
  • member icon


Reputation: 260
  • View blog
  • Posts: 1,419
  • Joined: 07-April 08

Re: Clauses

Posted 13 July 2012 - 05:24 AM

you need an operator such as AND or OR between your statements in the where clause. Proper SQL Syntax is

SELECT <Columns> FROM <tables> WHERE <Condition1> AND <Condition2> OR <Condition3>.....



see how i seperated each condition with an AND or an OR statement. Try adding that and see if it works.

Also you will want to look at using parameratized queries instead of inline like that. You open yourself up to sql injection attacks.

This post has been edited by rgfirefly24: 13 July 2012 - 05:28 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1