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) 请问怎么回事?