Getting Started
- From: "Rik Barker" <rik.barker@xxxxxxxxxxxxxx>
- Date: 15 Jun 2005 04:21:06 -0700
Hi,
I'm trying to get to grips with MS SQL and ADO at the same time. I've
got a working method of adding a record to a table with unique
constraints and getting back an autonumbered, but it seems decidely
sub-optimal.
I'm pretty sure there'll be a better way than this, can someone point
me in the right direction?
function TMSSQLImporter.AddLocation(const Location: string): Integer;
var
SQLCmd: string;
Qry: TADOQuery;
begin
Qry:=TADOQuery.Create(nil);
try
Qry.Connection:=FConnection;
SQLCmd:=Format('Insert Into Location (Location) VALUES
(''%s'')',[Location]);
try
FConnection.Execute(SQLCmd);
except
//Catch foreign key violations
end;
Qry.SQL.Text:=Format('Select LocnCode from Location where
Location=''%s''',[Location]);
Qry.Active:=True;
if Qry.RecordCount=0 then
Result:= -1
else
begin
Result:=Qry.FieldByName('LocnCode').AsInteger;
end;
finally
Qry.Free;
end;
end;
Cheers,
Rik
.
- Follow-Ups:
- Re: Getting Started
- From: Brian Bushay TeamB
- Re: Getting Started
- Prev by Date: MSDE 2000 SP4 no longer usable on Windows 98?
- Next by Date: TADOQuery and Date fields problem
- Previous by thread: MSDE 2000 SP4 no longer usable on Windows 98?
- Next by thread: Re: Getting Started
- Index(es):
Relevant Pages
|