调用存储过程时出现的问题(100)

  • 主题发起人 主题发起人 shijie
  • 开始时间 开始时间
S

shijie

Unregistered / Unconfirmed
GUEST, unregistred user!
存储过程为: CREATE OR ALTER procedure NEW_PROCEDURE ( ZHIWU varchar(15), NIANLING integer, XINGMING varchar(15)) as begin insert into SHIYAN (XINGMING, NIANLING, ZHIWU) values (:XINGMING, :NIANLING, :ZHIWU); end 表名为:shiyan 共有3个字段: XINGMING varchar(15)) NIANLING integer, ZHIWU varchar(15), 调用代码如下: unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Grids, DBGrids, DB, DBClient, SimpleDS, SqlExpr, MIDASLIB, DBXpress, FMTBcd, ComCtrls; type TForm1 = class(TForm) SQLConnection1: TSQLConnection; SimpleDataSet1: TSimpleDataSet; datasource1: TDataSource; btnConnect: TButton; btnCommit: TButton; btnQuery: TButton; DBGrid1: TDBGrid; lbl1: TLabel; SQLStoredProc1: TSQLStoredProc; Edit1: TEdit; Edit2: TEdit; Edit3: TEdit; procedure btnConnectClick(Sender: TObject); procedure btnQueryClick(Sender: TObject); procedure btnCommitClick(Sender: TObject); procedure DBGrid1DblClick(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.btnConnectClick(Sender: TObject); begin if SQLConnection1.Connected=true then SQLConnection1.Connected:=false; SQLConnection1.Params.Clear; SQLConnection1.Params.Values['user_name']:='SAIDE'; SQLConnection1.Params.values['password']:='19992009'; sqlConnection1.Params.Values['SQLDialect']:='3'; SQLConnection1.Params.Values['database']:=extractfilepath(paramstr(0))+'PM.FDB'; SQLConnection1.Connected:=true; showmessage('连接成功'); end; procedure TForm1.btnQueryClick(Sender: TObject); begin if not sqlConnection1.Connected then begin showmessage('请先连接'); exit; end; SimpleDataSet1.DataSet.CommandText:='select * from shiyan'; simpleDataSet1.Open; end; procedure TForm1.btnCommitClick(Sender: TObject); var P1:TParam; begin SQLStoredProc1.StoredProcName:='NEW_PROCEDURE'; P1:=TParam.Create(SQLStoredProc1.Params,ptInput); SQLStoredProc1.Params.Clear; SQLStoredProc1.Params[0].Name:='xingming'; SQLStoredProc1.Params[1].Name:='nianling'; SQLStoredProc1.Params[2].Name:='zhiwu'; SQLStoredProc1.Params.ParamByName('xingming').Value:=Edit1.text; SQLStoredProc1.Params.ParamByName('nianling').AsSmallint:=strtoint(Edit2.text); SQLStoredProc1.Params.ParamByName('zhiwu').Value:=edit3.Text; SQLStoredProc1.ExecProc; P1.Free; SimpleDataSet1.Refresh; end; end. 用鼠标点击btnCommitClick调用存储过程插入数据时,出现提示信息: List index out of bounds(0) 请问怎么回事?
 
List index out of bounds(0) 中文意思大概是参数越界
 
ZHIWU varchar, NIANLING integer, XINGMING varchar过程参数好像是不需要做长度限制的,delphi调用的时候,哪个是输入,哪个是输出参数
 
都是输入参数,我使ibexpert做的存储过程,调试通过了。
 
没有在存储过程控件中设置调用的存储过程的名称,而是在程序运行中确定调用的存储过程的名称,所以得建立参数对象(Params),估计是建立参数对象的过程出了错误。
 
SQLStoredProc1.Params.Clear; //参数清空//这里添加参数 //这里添加3个参数成员,你才能写参数信息//没有这个 就List index out of bounds(0) 参数越界SQLStoredProc1.Parameters.AddParameter; //参数0SQLStoredProc1.Parameters.AddParameter; //参数1SQLStoredProc1.Parameters.AddParameter; //参数2SQLStoredProc1.Params[0].Name:='xingming';
 
Params.Clear之后要重新创建参数,如Params.CreateParam()...
 
改了以后:procedure TForm1.btnCommitClick(Sender: TObject);beginSQLStoredProc1.StoredProcName:='GJGL';SQLStoredProc1.Params.Clear;SQLStoredProc1.Parameters.AddParameter;SQLStoredProc1.Parameters.AddParameter;SQLStoredProc1.Parameters.AddParameter;SQLStoredProc1.Parameters.AddParameter;SQLStoredProc1.Parameters.AddParameter;SQLStoredProc1.Parameters.AddParameter;with SQLStoredProc1.Params.CreateParam(ftstring, 'gonjumingcheng', ptInput) do AsString:= Edit1.text;with SQLStoredProc1.Params.CreateParam(ftString, 'jibendanwei', ptInput) do AsString:=Edit2.text;with SQLStoredProc1.Params.CreateParam(ftstring, 'baoyangzhuangkuang', ptInput) do AsString:=edit3.Text;with SQLStoredProc1.Params.CreateParam(ftFMTBCD, 'gourujiage', ptInput) do AsFMTBCD:=strtobcd(edit4.Text);with SQLStoredProc1.Params.CreateParam(ftInteger, 'shuliang', ptInput) do AsInteger:=strtoint(edit5.Text);with SQLStoredProc1.Params.CreateParam(ftstring, 'cunfangdidian', ptInput) do AsString:=edit6.Text;SQLStoredProc1.ExecProc;SimpleDataSet1.Refresh;end;编译通不过了。[Error] Unit1.pas(112): Undeclared identifier: 'Parameters'[Error] Unit1.pas(112): Missing operator or semicolon[Error] Unit1.pas(113): Undeclared identifier: 'Parameters'[Error] Unit1.pas(113): Missing operator or semicolon[Error] Unit1.pas(114): Undeclared identifier: 'Parameters'[Error] Unit1.pas(114): Missing operator or semicolon[Error] Unit1.pas(115): Undeclared identifier: 'Parameters'[Error] Unit1.pas(115): Missing operator or semicolon[Error] Unit1.pas(116): Undeclared identifier: 'Parameters'[Error] Unit1.pas(116): Missing operator or semicolon[Error] Unit1.pas(117): Undeclared identifier: 'Parameters'[Error] Unit1.pas(117): Missing operator or semicolon[Fatal Error] Project1.dpr(5): Could not compile used unit 'Unit1.pas'
 
SQLStoredProc1.Params.Clear;这一句一做,参数个数为零个。 后面这些肯定要出错的;SQLStoredProc1.Params[0].Name:='xingming'; SQLStoredProc1.Params[1].Name:='nianling'; SQLStoredProc1.Params[2].Name:='zhiwu'; 你自己加参数要指明参数类型拉
 
注释掉 SQLStoredProc1.Parameters.AddParameter; × 6 应该就好了。
 
SQLStoredProc1.Params.Clear;这一句一做,参数个数为零个。 后面这些肯定要出错的;SQLStoredProc1.Params[0].Name:='xingming'; SQLStoredProc1.Params[1].Name:='nianling'; SQLStoredProc1.Params[2].Name:='zhiwu'; 你自己加参数要指明参数类型拉 这些话我还没有看明白,请再点化一下。注释掉 SQLStoredProc1.Parameters.AddParameter; × 6 应该就好了。 请问这是什么意思?
 
多人接受答案了。
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
D
回复
0
查看
828
DelphiTeacher的专栏
D
D
回复
0
查看
844
DelphiTeacher的专栏
D
后退
顶部