qzlmq
asked on
how to use StoreProc of Sql Server 7.0 in delphi 4 application?
my storeproc is show as£º
CREATE PROCEDURE editguzi
( @ofn varchar(20),
@cardno varchar(20),
@usetime datetime,
@num int
)
AS
update guzi set
ofn=@ofn,usetime=@usetime, num=@num
where cardno=@cardno
in DELPHI 4 application(use storeproc componnent) £ºi use some code to call the storeproc:
with DM_guzi.sp_edit do
begin
//1.
parambyname('ofn').asstrin g:=EditOfn .Text ;//'
parambyname('cardno').asst ring:=Edit cardno.Tex t ;
parambyname('usetime').asd ate:=Editu setime.dat e;
//or parambyname('usetime').ass tring:=Dat eToStr(Edi tusetime.d ate);
parambyname('num').asstrin g:=Editnum .text;
Prepare;
execproc;
end;
but when i run application ,there is error occured .the error is show as
"parameter 'ofn','cardno'... no find",but when i modify 'ofn' to '@ofn',
'cardno' to '@cardno',however the error is also occure.
when i move 'Prepare' to position '1.',the error is disappear,but the 'update '
action is not really execute.
can you tell me what should i do ,thanks.
CREATE PROCEDURE editguzi
( @ofn varchar(20),
@cardno varchar(20),
@usetime datetime,
@num int
)
AS
update guzi set
ofn=@ofn,usetime=@usetime,
where cardno=@cardno
in DELPHI 4 application(use storeproc componnent) £ºi use some code to call the storeproc:
with DM_guzi.sp_edit do
begin
//1.
parambyname('ofn').asstrin
parambyname('cardno').asst
parambyname('usetime').asd
//or parambyname('usetime').ass
parambyname('num').asstrin
Prepare;
execproc;
end;
but when i run application ,there is error occured .the error is show as
"parameter 'ofn','cardno'... no find",but when i modify 'ofn' to '@ofn',
'cardno' to '@cardno',however the error is also occure.
when i move 'Prepare' to position '1.',the error is disappear,but the 'update '
action is not really execute.
can you tell me what should i do ,thanks.
Try to use StoredProc.Refresh befor using ParamByName
procedure name of stored procedure property must be named editguzi.
All you have to do is to delete all ';1' that are automaticaly given by delphi. The problem that appeared in the program occurs because of this ';1' not because of using '@'. But you also have to use '@' at the beginning of the paramater.
All you have to do is to delete all ';1' that are automaticaly given by delphi. The problem that appeared in the program occurs because of this ';1' not because of using '@'. But you also have to use '@' at the beginning of the paramater.
procedure name of stored procedure property must be named editguzi.
All you have to do is to delete all ';1' that are automaticaly given by delphi. The problem that appeared in the program occurs because of this ';1' not because of using '@'. But you also have to use '@' at the beginning of the paramater.
All you have to do is to delete all ';1' that are automaticaly given by delphi. The problem that appeared in the program occurs because of this ';1' not because of using '@'. But you also have to use '@' at the beginning of the paramater.
procedure name of stored procedure property must be named editguzi.
All you have to do is to delete all ';1' that are automaticaly given by delphi. The problem that appeared in the program occurs because of this ';1' not because of using '@'. But you also have to use '@' at the beginning of the paramater.
All you have to do is to delete all ';1' that are automaticaly given by delphi. The problem that appeared in the program occurs because of this ';1' not because of using '@'. But you also have to use '@' at the beginning of the paramater.
Try this :
..ParamByName('@name').Val ue :=
You declare the parameters in the stored procedure; no need to specify the type here. AsString, AsInteger are intended for retrieving data from an active dataset.
edit1.Text := dataset1.Fields.FieldbyNam e('Name'). AsString;
..ParamByName('@name').Val
You declare the parameters in the stored procedure; no need to specify the type here. AsString, AsInteger are intended for retrieving data from an active dataset.
edit1.Text := dataset1.Fields.FieldbyNam
ASKER
if i used storeproc.refresh,the error 'can't perform this operation' must be
show.i remove ';1' and change '.asstring' to '.value' and put
'prepare' before using ParamByNmae,i would get a error as
'invalid character value for cast specification'.if no change '.asstring'
,however the error occured.
can you give me a succeed example?
thanks.
show.i remove ';1' and change '.asstring' to '.value' and put
'prepare' before using ParamByNmae,i would get a error as
'invalid character value for cast specification'.if no change '.asstring'
,however the error occured.
can you give me a succeed example?
thanks.
Mostly I use a dataset with a stored procedure. Here's an example of a stored proc alone.
with sp_Add_user do
begin
Parameters.ParamByName('@p ers_nr').V alue := srcTodo.DataSet.Fields.Fie ldbyName(' Pnumber'). Asstring;
Parameters.ParamByName('@a dm_nr').Va lue := datasetAdmins.Fields.Field byname('Pn umber').As string;
ExecProc;
end;
If you want to use a sp with a dataset, set the command type prop to cmdStoredProc, then select the procedure in CommandText prop.
How do you connect to your database? Do you use ADO, BDE ...?
with sp_Add_user do
begin
Parameters.ParamByName('@p
Parameters.ParamByName('@a
ExecProc;
end;
If you want to use a sp with a dataset, set the command type prop to cmdStoredProc, then select the procedure in CommandText prop.
How do you connect to your database? Do you use ADO, BDE ...?
ASKER
i use odbc
I use odbc,and set storedprocname is delphi' default(like testproc;1).you must set the params to correct value at design time(server times it display not correct and corret it by myself). then i use the code you give and update the database successfully
ASKER
sorry ,i mayn't be listen clearly,how to 'corret it by myself' ,can you give me the codes? thanks!
It maybe show wrong params.ie. Delphi add a param named '0--Return_Value' to the Parmas's dialog(In design-time).
ASKER
sorry,i found key of the problem.
i use chinese word as parameter name,but delphi don't use chinese parameter name.when i change the parameter name from chinese to english.
everything is ok!
because i can't write the problem in chinese ,so cause the result!sorry!
thinks for everyone who help me.
i use chinese word as parameter name,but delphi don't use chinese parameter name.when i change the parameter name from chinese to english.
everything is ok!
because i can't write the problem in chinese ,so cause the result!sorry!
thinks for everyone who help me.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.