我现在想动态创建一个存储过程,然后调用它,请问这样对吗?不对应该如何改呢?
//想数据表StudentInfo中插入记录
procedure Button1Click(Sender: TObject);
var
strSQL : string;
str1,str2 :string;
begin
str1 := Edit1.text;
str2 := Edit2.text;
strSQL := 'CREATE PROCEDURE ProcTest'
+ ' @str_name char(50),@str_profession char(50)'
+ ' AS'
+ ' INSERT INTO StudentInfo([Name],[profession])'
+ ' VALUES(@str_name,@str_profession)
+ ' exec ProcTest str1,str2'; ADOQuery.Close;
ADOQuery.SQL.Clear ;
ADOQuery.ParamCheck := False;
ADOQuery.SQL.Add(strSQL);
ADOQuery.ExecSQL;end;
//想数据表StudentInfo中插入记录
procedure Button1Click(Sender: TObject);
var
strSQL : string;
str1,str2 :string;
begin
str1 := Edit1.text;
str2 := Edit2.text;
strSQL := 'CREATE PROCEDURE ProcTest'
+ ' @str_name char(50),@str_profession char(50)'
+ ' AS'
+ ' INSERT INTO StudentInfo([Name],[profession])'
+ ' VALUES(@str_name,@str_profession)
+ ' exec ProcTest str1,str2'; ADOQuery.Close;
ADOQuery.SQL.Clear ;
ADOQuery.ParamCheck := False;
ADOQuery.SQL.Add(strSQL);
ADOQuery.ExecSQL;end;
解决方案 »
- FROM有一个按钮,打开软件时搜索规定的注册,如果有资料就显示出“有情况”,反之
- 主窗体如何调用dll定义的函数和dll如何取得主窗体定义的公共变量
- 用Delphi开发的游戏,已经完成网络游戏功能!
- 开心+郁闷 散分
- ★★★软件产品(Delphi解释器)市场调查(请求版主勿删)★★★
- 请问我的好斑竹们,我用D7+SQL SERVER 2000+RAVE 5 做报表的时候的问题!
- 怎样隐含MDI主FORM?
- 我想做一个网页里使用的控件,但不需要form, 请问我用 d6该创建哪种类型的activex?
- 打印查询所得的数据的问题
- delphi里怎么把 String类型转换到 Tbitmap类型
- 关于窗口融合的问题!
- 当我对表Append后Post,马上再Edit再Post时,为什么会出错?
+ ' @str_name char(50),@str_profession char(50)'
+ ' AS'
+ ' INSERT INTO StudentInfo([Name],[profession])'
+ ' VALUES(@str_name,@str_profession)
+ ' exec ProcTest ''' + str1 + ''',''' + str2 + ''';
+ ' @str_name char(50),@str_profession char(50)'
+ ' AS'
+ ' INSERT INTO StudentInfo([Name],[profession])'
+ ' VALUES(@str_name,@str_profession) '//此處少一個單引號
+ ' exec ProcTest ''' + str1 + ''',''' + str2 + ''';
if not Exists(select * from sysobjects where xtype='P' and name='YourProductName')
//然後做你的事
还是这个错误
Project RemoteII.exe raised exception class EOleException with message '无效的 SQL 句法:需要的符号:AS。'. Process stopped. Use Step or Run to continue.
if not Exists(select * from sysobjects where xtype='P' and name='YourProductName')
|
|
type就行吧为什么要用xtype?
我用的是ACCESS数据库啊,现在我要一次向表中添加几千条数据,我应该如何做速度才快一点?我现在一条一条的添加,速度很慢,而且CPU资源耗用也很大,有时到100% ,不能用存储过程吗?那又有什么办法呢?
insert into StudentInfo([Name],[profession])
select 'A1' as [t1],'A2' as [t2] from StudentInfo
union all select 'A3' as [t1],'A4' as [t2] from StudentInfo
union all select 'A5' as [t1],'A6' as [t2] from StudentInfo
...
union all select 'A1000' as [t1],'A1001' as [t2] from StudentInfo'
然后
adoQuery.execSql用这种方法添加。看看速度是否提升。
insert into StudentInfo([Name],[profession])
select 'A1' as [t1],'A2' as [t2] from StudentInfo
union all select 'A3' as [t1],'A4' as [t2] from StudentInfo
union all select 'A5' as [t1],'A6' as [t2] from StudentInfo
...
union all select 'A1000' as [t1],'A1001' as [t2] from StudentInfo'
然后
adoQuery.execSql
这个是什么意思啊?我的数据是存在一个变量中,所以要用循环才能取到每个数。
也就是插入的数都是存在变量中,
是不是你給我留了言?我求求你下次給我留言的時候,
注明是哪個一個帖子好不好?我可是找了N久才找到這裡的呀 insert into StudentInfo([Name],[profession])
select 'A3','A4' union
select 'A5','A6'
這個SQL語句的意思是向StudentInfo表中插入
下面兩條記錄'A3','A4'
'A5','A6'你可以加入很多筆,記得每個Select用union連接
Insert into tablename(field1,field2)
select '1','1' union
select '2','2'所以用到AdoQuery的緩存更新
//下面是緩存更新的例子
procedure TForm1.Button1Click(Sender: TObject);
var
I : Integer;
dtStart, dtEnd: TDateTime;
begin
dtStart := Now;
AdoQuery1.LockType := ltBatchOptimistic;
AdoQuery1.DisableControls;
//記錄數:10000
for I := 0 to StrToIntDef(Edit1.text, -1) do
begin
AdoQuery1.Append;
AdoQuery1.FieldByName('name').AsString := Edit1.Text + '_' + IntToStr(i);
AdoQuery1.FieldByName('datebegin').AsDateTime := Now;
AdoQuery1.FieldByName('dateend').AsDateTime := Now;
AdoQuery1.Post;
end;
AdoQuery1.EnableControls;
dtEnd := Now;
Memo1.Lines.Add(FloatToStr((dtEnd - dtStart) / ( 1 / 24 / 3600)));
//Result = 0.985000189393759end;procedure TForm1.Button2Click(Sender: TObject);
var
dtStart, dtEnd: TDateTime;
begin
dtStart := Now;
AdoQuery1.UpdateBatch();
dtEnd := Now;
Memo1.Lines.Add(FloatToStr((dtEnd - dtStart) / ( 1 / 24 / 3600)));
//Result = 9.13099993485957
end;