Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Search in a DB HELP!!!

Posted on 1997-04-23
4
Medium Priority
?
162 Views
Last Modified: 2010-04-04
I need to write a program to enroll students. I need to search a student on name, lastname and number. In my IndexFieldNames of my table stands the following:
number;name;lastname
My statements are
Setkey;
FieldByName('Name').AsString := Edit.Text;
Gotokey;
However, it doesn't seems to work. how can I solve this. An earlier answer I got was to put an index on name but I think I did. If i didn't How do I this.HELP!HELP!HELP!HELP!HELP!
IT'S URGENT. Thanx to everyone who can help me, please???
0
Comment
Question by:940216td
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 2

Expert Comment

by:javiertb
ID: 1335642
Better removing this question if you already have one.
0
 

Expert Comment

by:wizzard
ID: 1335643
Just one thing that I need to know before solving your problem: what type of DB file are you using? I can send you an example program that will search for asked things ina DB file!

      C ya,
         WizzarD.
0
 

Accepted Solution

by:
aceman earned 150 total points
ID: 1335644
function Locate(const KeyFields: string; const KeyValues: Variant; Options: TLocateOptions): Boolean;

This is a clip from the Delphi help screen on the LOCATE method of a TTable component. Although the definition of the function includes the constant KeyFields the actual string listed does NOT have to be a KEY field in a database (thereby necessitating a primary key index). I have used this function to locate field values in many un-indexed, un-keyed tables regardless of the data table type. I have not tried this with tables other than local tables (dBase and Paradox are my usual tables so if you are using Oracle or SQL tables, this function may not apply) but give it a try. Implementation can be made as such

{this assumes the value to search is a text value}
var
  srchTxt:string;
begin
  srchTxt:=Edit1.Text;{get name / number to search for}
  if not table1.locate('StudentName',srchTxt,[loCaseInsensitive]) then
     {Student not located in table}
     ShowMessage('Unable to locate this student')
  else
     {show edit form, do something here, etc}

Alternately, you can use [loPartitialKey] instead of [loCaseInsensitive] will allow you to display partial string matches (e.g. HAM will display HAMMOND, HAMMERMILL, HAMILTON, etc).

You could also perform a query on a partial match, display the results in a dbGrid component, allow the user to click on the correct search, capture the student number in a variable, close the query, move back to the actual data table and use the LOCATE method to move the table cursor to that correct record (which WILL be found since you got it from that source to begin with) I like to allow both in my applications. If the user KNOWS the EXACT identifying number use it, otherwise, show me all possibilities starting with ??? (use HAM example) query the table with this EDIT1.TEXT value and do the above suggested choose and find procedures.

I hope this gives you the direction you need to accomplish your tasks!

Bill
0
 

Expert Comment

by:jmstolting
ID: 1335645
keep in mind that when you use gotokey, the search is performed on all the key fields. in your code you only assign the 'name' field, which will most likely generate no results because the index also contains the fields 'lastname' and 'number'.

if you want to search on only the 'name' field, use an index which only contains the 'name' field, or use KeyFieldCount
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question