Solved

how to use StoreProc of Sql Server 7.0 in delphi 4 application?

Posted on 2000-04-12
13
273 Views
Last Modified: 2010-04-04
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').asstring:=EditOfn.Text ;//'
          parambyname('cardno').asstring:=Editcardno.Text ;
          parambyname('usetime').asdate:=Editusetime.date;
 //or     parambyname('usetime').asstring:=DateToStr(Editusetime.date);
          parambyname('num').asstring:=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.
0
Comment
Question by:qzlmq
  • 4
  • 3
  • 2
  • +3
13 Comments
 
LVL 7

Expert Comment

by:Motaz
ID: 2710662
Try to use StoredProc.Refresh befor using ParamByName
0
 

Expert Comment

by:umitde
ID: 2710906
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.
0
 

Expert Comment

by:umitde
ID: 2710907
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.
0
 

Expert Comment

by:umitde
ID: 2710913
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.
0
 
LVL 1

Expert Comment

by:DonBartholomew
ID: 2711226
Try this :

..ParamByName('@name').Value :=

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.FieldbyName('Name').AsString;
0
 

Author Comment

by:qzlmq
ID: 2714778
  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.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Expert Comment

by:DonBartholomew
ID: 2715122
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('@pers_nr').Value := srcTodo.DataSet.Fields.FieldbyName('Pnumber').Asstring;
    Parameters.ParamByName('@adm_nr').Value := datasetAdmins.Fields.Fieldbyname('Pnumber').Asstring;
    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 ...?
0
 

Author Comment

by:qzlmq
ID: 2715423
i use  odbc
0
 
LVL 3

Expert Comment

by:shenqw
ID: 2731029
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
0
 

Author Comment

by:qzlmq
ID: 2737015
sorry ,i mayn't be listen clearly,how to 'corret it by myself' ,can you give me the codes? thanks!
0
 
LVL 3

Expert Comment

by:shenqw
ID: 2753089
It maybe show wrong params.ie. Delphi add a param named '0--Return_Value' to the Parmas's dialog(In design-time).
0
 

Author Comment

by:qzlmq
ID: 2754603
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.
 
0
 
LVL 15

Accepted Solution

by:
simonet earned 50 total points
ID: 2925970
Rewrite the stored procedure like this (note that there are no "(" and ")" in there):

CREATE PROCEDURE  editguzi
   @ofn    varchar(20),
   @cardno varchar(20),
   @usetime datetime,
   @num  int
 
AS
set nocount on
update guzi set ofn=@ofn, usetime=@usetime, num=@num
where cardno=@cardno  


Then in the TStoredProc component, set the databasename accordingly, then the storeprocedure name and then click on the ellipsis in the Parameters property. All the 4 parameters will be displayed.

You need now to set the DIRECTION and DATA TYPE of each parameter.

NOTE: don't change the info for the @RETURN_VALUE parameter.

All the four parameters are Input. The datatypes are string for the first 2 and datetime and integer for the other 2.

Then , in the Delphi code that calls it, pay attention to the data types of each parameter, and call it like this:

with DM_guzi.sp_edit do
         begin
          //1.
          parambyname('ofn').asstring:=EditOfn.Text ;//'
          parambyname('cardno').asstring:=Editcardno.Text ;
          parambyname('usetime').asdate:=Editusetime.date;
 //or     parambyname('usetime').asdatetime:=Editusetime.date;
          parambyname('num').asinteger:= strtoint(Editnum.text);
         
          Prepare;
          execproc;
         end;



*****************
yours,

Alex

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
how to manage invalidate between two tvirtualstringtree in same form? 1 104
code issue 8 100
Delphi - replicating a form 8 65
Error E2158 compiling with Delphi XE10 Seattle 2 88
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now