使用create table 后立即执行insert into,结果不识别新建立的表?

来源:百度知道 编辑:UC知道 时间:2024/06/21 17:19:16
strsql := 'create Table "bbb" ("b1" Integer)';
with dm.ClientDataSet_Public do
begin
if Active then Active:=True;
CommandText := strsql;
Execute;
end;

strsql := 'insert into "bbb" values(10)';
with dm.ClientDataSet_Temp do
begin
if Active then Active:=True;
CommandText := strsql;
Execute;
end;
我是在三层模式下编程的,需要在程序中动态建表。如果在程序中先动态建表,退出程序,然后再运行程序中的(insert into ...)则正确,如果建表后,马上再insert into。。。则就不识别新建的表,不知为什么?我使用Delphi与InterBase7.1数据库。
谢谢各位仔细一些,是 如果建表create table 后,马上再insert into。。。则就不识别新建的表

首先
strsql:= 'create Table bbb(b1 Int)';这样写就行了
然后在建表时通常考虑该表是否存在,即:
strsql:= 'if exists(select name from sysobjects where name='bbb' and type='u') begin drop table bbb end ';
strsql:=strsql+' create Table bbb(b1 Int) '

我用adoquery重来没碰过这种情况,我是在两层结构下开发的,用execsql,都可以

呵呵

为什么不先把表建好 这样我觉得麻烦了!

如果是SQL是不是要先导入数据库啊