Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > DB-Aware

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 03-05-2003, 01:01 AM
DJK DJK is offline
Senior Member
 
Join Date: Aug 2002
Posts: 1,379
Default Show search string only (DB)

I have a DBGrid (Jet MS-Access)

And I have a table called "goods", now I let the user search in a editbox for a certain vendor.

Now what I want is when the user enteres a vendor in the editbox and searches it needs to show only those vendors in my DBGrid, so not all the others ...

Tnx
Reply With Quote
  #2  
Old 03-05-2003, 01:10 AM
phear phear is offline
Senior Member
 
Join Date: Mar 2001
Posts: 325
Default RE: Show search string only (DB)

Hi.
Use the Locate method in the Dataset (query) connected to it.

pHeAr
http://phear.fr.st
Reply With Quote
  #3  
Old 03-05-2003, 01:25 AM
DJK DJK is offline
Senior Member
 
Join Date: Aug 2002
Posts: 1,379
Default RE: Show search string only (DB)

Hi,

I never used these Dataset commands... could you give me a example like I want to :

When a user enters a vendor in a editbox and searches the DBGrid displays only those vendors from my database goods in ASC order ?
Reply With Quote
  #4  
Old 03-05-2003, 01:27 AM
phear phear is offline
Senior Member
 
Join Date: Mar 2001
Posts: 325
Default RE: Show search string only (DB)

The locate just points the query cursor on a record.
Look at the delphi help on the locate method of a TADOQuery, it explains clearly how to use it.

pHeAr
http://phear.fr.st
Reply With Quote
  #5  
Old 03-05-2003, 01:34 AM
phear phear is offline
Senior Member
 
Join Date: Mar 2001
Posts: 325
Default RE: Show search string only (DB)

Just do this :

ADOQuery1.Locate('Vendor', Edit1.Text, [loCaseInsensitive, loPartialKey]);


pHeAr
http://phear.fr.st
Reply With Quote
  #6  
Old 03-05-2003, 01:36 AM
DJK DJK is offline
Senior Member
 
Join Date: Aug 2002
Posts: 1,379
Default RE: Show search string only (DB)

I looked at the help and I think this is a example they give :

with ADOTable1 do
Locate('Company;Contact;Phone', VarArrayOf(['Sight Diver', 'P', '408-431-1000']), [loPartialKey]);

But to be honest , this goes way above my head

I tried to puzzle that line for my circumstances and this is what I got :

with ADOQuerry1 do
Locate('Vendor', VarArrayOf(['???', '???', '???']), [loPartialKey]);

I have no clue with I have to enter in that "VarArrayOf" (or maybe I may delete that part ?) and I keep that "lopartialkey" as again, I don't know if I can delete it or not

The only thing I want is that it searches for the string in my editfield in the vendor field in my database and gives me those vendors as result in my DBGrid...

I'm sorry for the trouble I cause :'(
Reply With Quote
  #7  
Old 03-05-2003, 01:40 AM
phear phear is offline
Senior Member
 
Join Date: Mar 2001
Posts: 325
Default RE: Show search string only (DB)

see my post before yours :

ADOQuery1.Locate('Vendor', Edit1.Text, [loCaseInsensitive, loPartialKey]);

;-)

pHeAr
http://phear.fr.st
Reply With Quote
  #8  
Old 03-05-2003, 01:41 AM
DJK DJK is offline
Senior Member
 
Join Date: Aug 2002
Posts: 1,379
Default RE: Show search string only (DB)

Hi

Soz for my previous reply, didn't read your next one at that time.

That locate doesn't give me errors but it only "tags" the first matching string it finds in my vendor field.

I actually wants that it only shows the matching vendors (with there other fields) in my DBGrid, so let's say, just a example, my table in access contains this :

Number - Product - Vendor - Distributer
1 Prod1 Vend1 Dis1
2 Prod2 Vend2 Dis2
3 Prod3 Vend1 Dis3
4 Prod4 Vend1 Dis4
5 Prod5 Vend3 Dis5

As you can see there are 3 vendor "1" in my database, now when a user types "vend1" in my edit and presses the button my DBGrid should change to display this :

Number - Product - Vendor - Distributer
1 Prod1 Vend1 Dis1
3 Prod3 Vend1 Dis3
4 Prod4 Vend1 Dis4


I hope this is possible
Reply With Quote
  #9  
Old 03-05-2003, 01:42 AM
DJK DJK is offline
Senior Member
 
Join Date: Aug 2002
Posts: 1,379
Default RE: Show search string only (DB)

Hi

Soz for my previous reply, didn't read your next one at that time.

That locate doesn't give me errors but it only "tags" the first matching string it finds in my vendor field.

I actually wants that it only shows the matching vendors (with there other fields) in my DBGrid, so let's say, just a example, my table in access contains this :

Number - Product - Vendor - Distributer
1 Prod1 Vend1 Dis1
2 Prod2 Vend2 Dis2
3 Prod3 Vend1 Dis3
4 Prod4 Vend1 Dis4
5 Prod5 Vend3 Dis5

As you can see there are 3 vendor "1" in my database, now when a user types "vend1" in my edit and presses the button my DBGrid should change to display this :

Number - Product - Vendor - Distributer
1 Prod1 Vend1 Dis1
3 Prod3 Vend1 Dis3
4 Prod4 Vend1 Dis4


I hope this is possible
Reply With Quote
  #10  
Old 03-05-2003, 01:52 AM
phear phear is offline
Senior Member
 
Join Date: Mar 2001
Posts: 325
Default RE: Show search string only (DB)

ADOQuery1.Close();
ADOQuery1.SQL.Clear();
ADOQuery1.SQL.Add('SELECT * FROM Goods where Vendor = ''' + Edit1.Text + ''' ORDER BY Vendor ASC');
ADOQuery1.Open();

You juste have to change the SQL. Note that you also have to check for case (upper or lower) and maybe use the "like" keyword in sql, but i can't help you more cause i don't know acces and i don't know hos it's sql works.
Hope this helps.

pHeAr
http://phear.fr.st
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 06:27 AM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2019, vBulletin Solutions, Inc.