|
-
February 2nd, 2010, 09:25 AM
#16
Re: PLs pls help me!!!!!!!!!
That's not the propblem. If you look at the following code segment
Code:
With rs2
.Open strSQL, conn1, adOpenStatic, adLockOptimistic
Set MSHFlexGrid1.DataSource = rs2
If .EOF ...
you'd note that immediately after the rs2.Open statement I have connected the flexgrid to the datasource of rs2. The result of the Open statement should immediately show in the grid.
At the time of open the sql line is
Select * from personaldetails where Student_name like "c*";
and the results are zero
Change the sql to
Select * from personaldetails where Student_name like "chris";
and it finds the record where Student_name is chris.
So why does the Like "c*" not find chris, too? That's here the question.
I'd anyway advise more changes to the code belonging the .EOF, but this makes no sense as long as the Like statement does not deliver records as expected.
-
February 2nd, 2010, 09:51 AM
#17
Re: PLs pls help me!!!!!!!!!
Ok, I seem to have bumped into the solution. It is the "*" operator.
I don't know why, but if you look for the syntax of the Like operator in SQL statements you'll find two different descriptions, one denoting the "*" character as wildcard, the other one wants the "%" in this place. For some reason (maybe depending on the version of Access database) in your studentdetails.mdb the "%" sign works as a wildcard.
I have stripped down your code from redundant repetitions you did in the Case clauses to show you how the function you want is easily accomplished.
Just put this code into Text1_Change():
Code:
Private Sub Text1_Change()
conndb
Set rs2 = New ADODB.Recordset
Dim strSQL As String, sqlquery As String
sqlquery = "Select * from personaldetails"
Select Case Combo1.Text
Case Is = "Name"
sele = 1
MSHFlexGrid1.LeftCol = 1
strSQL = sqlquery & " where Student_name like """ & Trim(Text1.Text) & "%"";"
Case Is = "ID No"
sele = 2
MSHFlexGrid1.LeftCol = 0
strSQL = sqlquery & " where ID like '*" & Trim(Text1.Text) & "*'"
Case Is = "Last Name"
sele = 3
MSHFlexGrid1.LeftCol = 2
strSQL = sqlquery & " where Last_name like '" & Trim(Text1.Text) & "*'"
End Select
With rs2
.Open strSQL, conn1, adOpenStatic, adLockOptimistic
Set MSHFlexGrid1.DataSource = rs2
If .EOF Then
MsgBox "The Search Criteria Have Been Complete." & vbCrLf & "Or Result Not Found In Database!!", vbExclamation, "Search Error Failed."
SendKeys "{Home}+{End}"
'On Error Resume Next
End If
End With
'MSHFlexGrid1.Refresh
Label2.Visible = True
End Sub
You'll note that the Select Case is only used to determine the SQL string (using "%" as wildcard) and then the database is accessed. You need not repeat this code three times, too.
Also the complete ELSE clause of the If .EOF seemed useless, yet even wrong, so I left it away.
I think this is what you attempted and I'm sure you can now go on with it.
-
February 2nd, 2010, 09:53 AM
#18
Re: PLs pls help me!!!!!!!!!
And please also note how easy it is to read and understand code if you keep indendation logically structured.
-
February 2nd, 2010, 10:15 AM
#19
Re: PLs pls help me!!!!!!!!!
wow i didnt see ya last post sorry!!!
u r genius.........
it works thnks bro!!!!!!!!!!!!!!!!!!
u were right ill surly follow ur instructions....................
-
February 2nd, 2010, 10:24 AM
#20
Re: PLs pls help me!!!!!!!!!
thnks a lot.u saved me..
can i consult ya if there are any further probs???
-
February 2nd, 2010, 10:13 PM
#21
Re: PLs pls help me!!!!!!!!!
 Originally Posted by WoF
And please also note how easy it is to read and understand code if you keep indendation logically structured. 
I noticed that I had to use & to get a phone number to work with LIKE, but names worked with *
-
February 3rd, 2010, 10:08 AM
#22
Re: PLs pls help me!!!!!!!!!
@analyse300: Sure feel free to come back any time.
@David:
What intrigues me is the two different explanations.
The Like statement in VB works with the "*" as a wildcard, sure. That's in the manual.
But then you lookup the SQL Like statement and find two different explanations.
One says "*" is the wildcard, the other says "%" is the wildcard.
After my testing with the database of the OP, most obviously the "%" is the wildcard.
The "*" produces an emty recordset
The starnge thing is, when opening that particular database with access and create an adequate query, you have to use "*" as a wildcard to produce a result.
Doing the same thing via ADO.Recordset.Open method you HAVE TO use the "%". I tried to copy the query from Access (with the "*") and it didn't work. Changing * to % worked immediately.
I'm a bit baffled about that one and have not yet worked out the reason for it. Are there different versions of SQL connected with the ADO library?
-
February 3rd, 2010, 06:33 PM
#23
Re: PLs pls help me!!!!!!!!!
Might be different versions of the ADOC library. I learned the hard way a few years ago, thanks to pete (wonder where he went?)
-
February 5th, 2010, 12:38 PM
#24
Re: PLs pls help me!!!!!!!!!
 Originally Posted by dglienna
Might be different versions of the ADOC library. I learned the hard way a few years ago, thanks to pete (wonder where he went?)
I have seen that in more modern languages like C# they always use '%' as a wildcard while when I was working with older versions of ADODB I always had to use '*' as wildcard. But thats simple my experience
 Jonny Poet
To be Alive is depending on the willingsness to help others and also to permit others to help you. So lets be alive. !
Using Code Tags makes the difference: Code is easier to read, so its easier to help. Do it like this: [CODE] Put Your Code here [/code]
If anyone felt he has got help, show it in rating the post.
Also dont forget to set a post which is fully answered to 'resolved'. For more details look to FAQ's about Forum Usage. BTW I'm using Framework 3.5 and you ?
My latest articles :
Creating a Dockable Panel-Controlmanager Using C#, Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7
-
February 5th, 2010, 04:25 PM
#25
Re: PLs pls help me!!!!!!!!!
Hello,
May I ? ===>>
http://msdn.microsoft.com/en-us/libr...ice.10%29.aspx
The "The ADO monkey wrench" paragraph is the one we have to read with more attention. Other wildcard characters changed, too...
-
February 5th, 2010, 07:55 PM
#26
Re: PLs pls help me!!!!!!!!!
OK. A bit older than ADO versions, it's the old DAO library in Access 97 (and VB6)
-
February 8th, 2010, 02:17 PM
#27
Re: PLs pls help me!!!!!!!!!
Well, this all sounds as if we would have to run a testroutine to determine which character is wild.
If Select * from table where name like "*" returns no record, we have to try "%"?
Interesting to hear about the ALike operator. Never heard before. And this one always uses "%"?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|