Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Database Problems

Status
Not open for further replies.

sOlsTiCezA

Programmer
Mar 20, 2002
17
ZA
Hi

I want to insert a record into a table, and before posting, I want to retrieve the value of the auto incremement field. Is this possible ?

Also, I use the locate function of TDataset to retrieve the first record that matches specified criteria, but how do i retireve the following records that match the same criteria.

Thanks
 
1) Can you go to the last record and retreive it's number before you do the insert? I have no idea when that number is assigned. If it's assigned on insert, then you should be able to retrieve it with a fieldbyname type of thing prior to post.

2) You probably need to set up a secondary index to do this (take a look in the help for SetKey/GotoKey), but this is how we handle it:

table1.IndexName:='VarName_ind';
table1.Setkey;
table1['VarName']:=ASTR_VarName;
table1['FormName']:=ASTR_FormName;
table1['Page_VersionNumber']:=ASTR_VersionNumber;
if table1.GotoKey then
table1.Edit
else
table1.insert;
Brian
"There are 2 kinds of people in the world, those that divide people into two groups and those that don't. I belong to the second group." - tag line I stole
 
Sorry, that isn't going to work (setkey/gotokey). Don't know what I was thinking. I'll look for the real answer if no one else gives you one sooner. Brian
"There are 2 kinds of people in the world, those that divide people into two groups and those that don't. I belong to the second group." - tag line I stole
 
After getting some caffiene in my system, I can think of two options for you.

1) You can filter your dataset, and use table.first and table.next until you hit .eof. If you do this, it's best to save your current table filter (if you use one) and filter state (.filtered) and restore those settings when you are done. This will work with non-indexed searches. This is apparently what locate does internally (according to team B posts on the borland.public groups)

2) You can use a query to return the records you want. Brian
"There are 2 kinds of people in the world, those that divide people into two groups and those that don't. I belong to the second group." - tag line I stole
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top