| View previous topic :: View next topic |
| Author |
Message |
Brad Prendergast Guest
|
Posted: Thu Jan 05, 2006 6:22 pm Post subject: Re: How can I access the fields of TADOStoredProc? |
|
|
Keith G Hicks <krh (AT) comcast (DOT) net> wrote in message
<43bd68d3$1 (AT) newsgroups (DOT) borland.com>:
| Quote: | I'm creating a TADOSToredProc in code and using it to run an MS SQL 2k
stored procedure. The backend procedure creates some new rows in
several tables. Then the procedure returns a select statement (not a
return parameter). The select statement has 1 record and 2 fields in
it. How can I access them from my delphi code?
The last line of the backend procedure is like this:
SELECT CustID, CustState From tblCusts Where CustName = @sNewCustName
Here's my front end code:
stprAddCusts := TADODataSet.Create(nil);
with stprAddCusts do
try
ProcedureName := 'spAddCusts';
Connection := globalCnn;
Prepared := False;
with Parameters do
begin
Refresh;
ParamByName('@sNewCustName).Value := sNewCustName;
end;
Prepared := true;
Active := true;
ExecProc;
// >>>>>> HERE'S WHERE I WANT TO ACCESS THE 2 FIELDS (CustID &
CustState) RETURNED BY THE PROCEDURES SELECT STATMENT
Prepared := false;
finally
Free;
end;
If I have to use a TAdoDataset instead, I tried that and couldn't
figure out the right way so if that's the solution I need some
details.
Thanks,
Keith
|
I think I follow you ---
you want to work with the sp recordset -
var
RecordSet: _RecordSet;
RecordSet:= stprAddCusts.RecordSet;
then you can do with it as any other recordset...
--
Brad Prendergast
"The only difference between me and a madman is that I'm not mad." --
Salvador Dali (1904 - 1989)
|
|
| Back to top |
|
 |
Keith G Hicks Guest
|
Posted: Thu Jan 05, 2006 6:45 pm Post subject: How can I access the fields of TADOStoredProc? |
|
|
I'm creating a TADOSToredProc in code and using it to run an MS SQL 2k
stored procedure. The backend procedure creates some new rows in several
tables. Then the procedure returns a select statement (not a return
parameter). The select statement has 1 record and 2 fields in it. How can I
access them from my delphi code?
The last line of the backend procedure is like this:
SELECT CustID, CustState From tblCusts Where CustName = @sNewCustName
Here's my front end code:
stprAddCusts := TADODataSet.Create(nil);
with stprAddCusts do
try
ProcedureName := 'spAddCusts';
Connection := globalCnn;
Prepared := False;
with Parameters do
begin
Refresh;
ParamByName('@sNewCustName).Value := sNewCustName;
end;
Prepared := true;
Active := true;
ExecProc;
// >>>>>> HERE'S WHERE I WANT TO ACCESS THE 2 FIELDS (CustID &
CustState) RETURNED BY THE PROCEDURES SELECT STATMENT
Prepared := false;
finally
Free;
end;
If I have to use a TAdoDataset instead, I tried that and couldn't figure out
the right way so if that's the solution I need some details.
Thanks,
Keith
|
|
| Back to top |
|
 |
Keith G Hicks Guest
|
Posted: Thu Jan 05, 2006 7:25 pm Post subject: Re: How can I access the fields of TADOStoredProc? |
|
|
Well I figured out the TAdoDataset way to do this so I dont' need help on
that but I'd still like to know if it's possible to so it using
TAdoStoredProc
Thanks,
Keith
|
|
| Back to top |
|
 |
Brian Hollister Guest
|
Posted: Thu Jan 05, 2006 7:49 pm Post subject: Re: How can I access the fields of TADOStoredProc? |
|
|
Keith,
Try using it like so;
adosp.FieldByName('YourFieldName'). Value
AsString
Any other
AsXXX you want
hth,
brian
--
Got a big event coming up? Let us
help coordinate your event. For more
visit www.kissemgoodbye.com
"Keith G Hicks" <krh (AT) comcast (DOT) net> wrote
| Quote: | Well I figured out the TAdoDataset way to do this so I dont' need help on
that but I'd still like to know if it's possible to so it using
TAdoStoredProc
Thanks,
Keith
|
|
|
| Back to top |
|
 |
Perry Way Guest
|
Posted: Thu Jan 05, 2006 9:29 pm Post subject: Re: How can I access the fields of TADOStoredProc? |
|
|
Hi Keith,
If you use the call Open() instead of ExecProc() it will execute the
procedure as well as keep any returned datasets opened, whereas ExecProc()
only executes the procedure. You can then access the dataset the same way
as you would a query, perhaps you wish to use FieldByName() since you know
the field names you want. If your procedure returns more than one dataset,
then you can call NextDataset(), but I think from your post this is more
than you require here...
PW
|
|
| Back to top |
|
 |
Keith G Hicks Guest
|
Posted: Fri Jan 06, 2006 3:45 am Post subject: Re: How can I access the fields of TADOStoredProc? |
|
|
Thanks everyone for your help. I ended up figuring out how to handle what I
needed to do using TAdoDataset. The backend procedure runs and does what
it's supposed to do and I have access to the fields in the dataset that it's
sending back. I should be ok. I will however hang on to the information you
all posted as it should be useful to me at some point.
-keith
|
|
| Back to top |
|
 |
|