By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,064 Members | 1,449 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,064 IT Pros & Developers. It's quick & easy.

Using Like Operator While Searching

P: 21
HELLO JI
i wish to get records from file having name candidate_detail. for this i use following coding.it never give me any error but can't show record available in file.

i m sending the code as below:

Private Sub Command3_Click()
Set rs = New adodb.Recordset
rs.Open "Select * from Candidate_Detail where Candidate_Name like ' " & (Text1) & " '", con, adOpenForwardOnly, adLockOptimistic

If rs.EOF = True Then
MsgBox "No Such Records"
Else
Text2 = rs.Fields(2)
Text3 = rs.Fields(3)
Text4 = rs.Fields(4)
Text5 = rs.Fields(5)
Text6 = rs.Fields(6)
Text7 = rs.Fields(7)
Text8 = rs.Fields(8)
Text9 = rs.Fields(9)
Text10 = rs.Fields(10)
Text11 = rs.Fields(11)
Text12 = rs.Fields(0)
End If
end sub
Sep 1 '07 #1
Share this Question
Share on Google+
5 Replies


debasisdas
Expert 5K+
P: 8,127
in sql for searching the syntax is

Expand|Select|Wrap|Line Numbers
  1. Select * from Candidate_Detail where Candidate_Name like '%das%'
modify your sql string accordingly.
Sep 1 '07 #2

hariharanmca
100+
P: 1,977
HELLO JI
i wish to get records from file having name candidate_detail. for this i use following coding.it never give me any error but can't show record available in file.

i m sending the code as below:

Private Sub Command3_Click()
Set rs = New adodb.Recordset
rs.Open "Select * from Candidate_Detail where Candidate_Name like ' " & (Text1) & " '", con, adOpenForwardOnly, adLockOptimistic

If rs.EOF = True Then
MsgBox "No Such Records"
Else
Text2 = rs.Fields(2)
Text3 = rs.Fields(3)
Text4 = rs.Fields(4)
Text5 = rs.Fields(5)
Text6 = rs.Fields(6)
Text7 = rs.Fields(7)
Text8 = rs.Fields(8)
Text9 = rs.Fields(9)
Text10 = rs.Fields(10)
Text11 = rs.Fields(11)
Text12 = rs.Fields(0)
End If
end sub

Just check your query

"Select * from Candidate_Detail where Candidate_Name like ' " & (Text1) & " '",

like '<Space>" & (Text1) & "<Space>'"

so if you give 'vandanasridhar' then it will look for '<Space>vandanasridhar<Space>'
Just check that and why you are not using proper property for controles like

Text1.Text is given as Text1
Sep 1 '07 #3

debasisdas
Expert 5K+
P: 8,127
Just check your query
"Select * from Candidate_Detail where Candidate_Name like ' " & (Text1) & " '",
like '<Space>" & (Text1) & "<Space>'"
so if you give 'vandanasridhar' then it will look for '<Space>vandanasridhar<Space>'
Just check that and why you are not using proper property for controles like
Text1.Text is given as Text1
Where is the space in the sql part ?
and TEXT is the default property of the TextBox control , so specify that property is totally optional.
Sep 1 '07 #4

hariharanmca
100+
P: 1,977
Where is the space in the sql part ?
and TEXT is the default property of the TextBox control , so specify that property is totally optional.
Just check the #1 Sql query

"Select * from Candidate_Detail where Candidate_Name like '<Space>" & (Text1) & "<Space>'",
He is giving the space between single quote(') and double quotes(")

yes text property is optional but that is not good Practice to write a bulky code.
Sep 1 '07 #5

QVeen72
Expert 100+
P: 1,445
HELLO JI
i wish to get records from file having name candidate_detail. for this i use following coding.it never give me any error but can't show record available in file.

i m sending the code as below:

Private Sub Command3_Click()
Set rs = New adodb.Recordset
rs.Open "Select * from Candidate_Detail where Candidate_Name like ' " & (Text1) & " '", con, adOpenForwardOnly, adLockOptimistic

If rs.EOF = True Then
MsgBox "No Such Records"
Else
Text2 = rs.Fields(2)
Text3 = rs.Fields(3)
Text4 = rs.Fields(4)
Text5 = rs.Fields(5)
Text6 = rs.Fields(6)
Text7 = rs.Fields(7)
Text8 = rs.Fields(8)
Text9 = rs.Fields(9)
Text10 = rs.Fields(10)
Text11 = rs.Fields(11)
Text12 = rs.Fields(0)
End If
end sub
Hi,

if ur backend database is Access then:

Expand|Select|Wrap|Line Numbers
  1. rs.Open "Select * from Candidate_Detail where Candidate_Name like '*" & (Text1) & "*'", con, adOpenForwardOnly, adLockOptimistic
  2.  
  3.  
Replace * with % if backend is Oracle or MS SQL


REgards
Veena
Sep 2 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.