Page 1 of 1

Access stored procedures with parameters - Newbee question

Posted: Thu 25 Aug 2005 12:47
by terjelarsen
Hi!

I'm new to this forum and the components. I've used the all components but the storedproc component.

The question is quite simpel I've a stored procedure I'd like to pase parameters to and execute. The stored procedure:
------------------------------------------------------------------------------------
-- =============================================
-- Create procedure
-- =============================================
-- creating the store procedure

CREATE PROCEDURE SettInnSamtale
@KUNDENR varchar(10),
@DATO varchar(8),
@TID varchar(8),
@ANR varchar(20),
@BNR varchar(30),
@BRUKER varchar(10),
@DESTINASJON varchar(40),
@VARIGHET varchar(8),
@FAKTURERT varchar(1),
@INNPRIS float,
@UTPRIS float,
@DB float,
@Songfaktura varchar(20)
AS
BEGIN
INSERT INTO Samtaler(KUNDENR,DATO,TID,ANR,BNR,BRUKER,DESTINASJON,VARIGHET,FAKTURERT,INNPRIS,UTPRIS,DB,Songfaktura)
VALUES (@KUNDENR,@DATO,@TID,@ANR,@BNR,@BRUKER,@DESTINASJON,@VARIGHET,@FAKTURERT,@INNPRIS,@UTPRIS,@DB,@Songfaktura)

END


GO
-------------------------------------------------------------------------------

How do I access this from Delphi with the components?

Thanks in advance

Terje

Posted: Thu 25 Aug 2005 13:55
by terjelarsen
I found the soulution.

Thanks anyway.

Terje

Posted: Sat 03 Sep 2005 23:16
by eferres
Wouldn't you like to share your findings? I have the same problem that you had but I'm less lucky... :oops: :oops:

Posted: Sun 04 Sep 2005 09:30
by terjelarsen
Hi!

Sure I'll share my findings.

Here's the procedure I use:

procedure TForm1.PostTilDataBase;
begin
MSStoredProc1.Params.ParamValues['KUNDENR'] := CDRRec.KundeNr;
MSStoredProc1.Params.ParamValues['DATO'] := CdrRec.Dato;
MSStoredProc1.Params.ParamValues['TID'] := CdrRec.StartTid;
MSStoredProc1.Params.ParamValues['ANR'] := CdrRec.Anr;
MSStoredProc1.Params.ParamValues['BNR'] := CdrRec.BNr;
MSStoredProc1.Params.ParamValues['BRUKER'] := CdrRec.Bruker;
MSStoredProc1.Params.ParamValues['DESTINASJON'] := CdrRec.Destinasjon;
MSStoredProc1.Params.ParamValues['VARIGHET'] := CdrRec.Varighet;
MSStoredProc1.Params.ParamValues['FAKTURERT'] := CdrRec.Fakturtert;
MSStoredProc1.Params.ParamValues['INNPRIS'] := CdrRec.InnPris;
MSStoredProc1.Params.ParamValues['UTPRIS'] := CdrRec.UtPris;
MSStoredProc1.Params.ParamValues['DB'] := CdrRec.DB;
MSStoredProc1.Params.ParamValues['Songfaktura'] := CdrRec.SongFaktura;
MSStoredProc1.Execute;
end;

I hope this make it clearer.

Kind regards
Terje

Posted: Sun 04 Sep 2005 11:24
by eferres
It worked! Thanks indeed! My problem was that I was naming my StoredProcs 'SP_*' and the component didn't recognize them correctly. Renaming them with other names, made them work correctly: with your code and with other codes (as ParamByName, for example). Well, I share this one for other beginners as myself...

Posted: Mon 05 Sep 2005 11:41
by Ikar
> I was naming my StoredProcs 'SP_*' and the component didn't recognize them correctly.

Please specify your exact SDAC version

Posted: Mon 05 Sep 2005 20:36
by eferres
In the "What's new" file it's quoted "21-Mar-02 New features in SDAC 1.30" as the newer date...

Posted: Tue 06 Sep 2005 07:51
by Ikar
So, you use very old SDAC version. We advice to upgrade it.

Posted: Tue 06 Sep 2005 14:31
by Guest
It's rather my Delphi 4 I have to upgrade! I see no later SDAC for it...
By the way, does anybody have a code example to execute a StoredProc at run time, from the assignment of a new value for the StoredProcName until the final execution? If I prepare the SP component at design time, assigning values for each parameter, values that I may change at run time, the component works fine. But if I want to use the same component to execute different StoredProcs in the server, I recieve an error message stating something like "too many steps in the OLE DB instruction..." (original in portuguese...)

Posted: Wed 07 Sep 2005 14:52
by Ikar
Please specify exact SDAC version from menu SDAC -> About

Posted: Wed 07 Sep 2005 15:04
by Ikar
> But if I want to use the same component to execute different StoredProcs
> in the server
> I receive an error message

Please send us (sdac*crlab*com) a complete small sample that demonstrates the problem.