判断表是否存在: if exists (select * from sysobjects where id = object_id(N'[表名]') and OBJECTPROPERTY(id, N'IsUserTable') = 1) drop table [表名]
判断表存在的方法: procedure TForm1.Button1Click(Sender: TObject); var TableList:TstringList; TableName:string; begin TableName:='Table1'; TableList:=Tstringlist.Create; LogADOConnection1.GetTableNames(TableList); if TableList.IndexOf(TableName)>=0 then//如果表存在 ...... end; 2.根据"'ADOQuery1: CommandText does not return a result set'" 可以断定你的代码大概如下: adoquery1.sql.add('select......'); adoquery1.open;//错误 应该改成adoquery1.execsql; 其它的最好贴出原码!
我已解决问题。以下是我用query做的,跟adoquery应该一样。 with query1 do begin close; sql.clear; sql.add('select * from newtable'); prepare; open; end; if query1.Active =true then begin showmessage('newtable is exists'); exit; end; 方法是笨了点,不过绝对可用。顺便问一下,能否动态的建立表名?比如说已经判断newtable已经存在,则建立newtable1,newtable1存在,则建立newtable2。 以下方法可以得到表的结构! with query1 do begin close; sql.clear; sql.add('select * into newtable from 模拟量表'); prepare; execsql; close; sql.clear; sql.add('delete from newtable'); prepare; execsql; end; 能否给我分?谢谢!我们再交流:[email protected]
if exists (select * from sysobjects where id = object_id(N'[表名]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [表名]
procedure TForm1.Button1Click(Sender: TObject);
var
TableList:TstringList;
TableName:string;
begin
TableName:='Table1';
TableList:=Tstringlist.Create;
LogADOConnection1.GetTableNames(TableList);
if TableList.IndexOf(TableName)>=0 then//如果表存在
......
end;
2.根据"'ADOQuery1: CommandText does not return a result set'"
可以断定你的代码大概如下:
adoquery1.sql.add('select......');
adoquery1.open;//错误
应该改成adoquery1.execsql;
其它的最好贴出原码!
with query1 do
begin
close;
sql.clear;
sql.add('select * from newtable');
prepare;
open;
end;
if query1.Active =true then
begin
showmessage('newtable is exists');
exit;
end;
方法是笨了点,不过绝对可用。顺便问一下,能否动态的建立表名?比如说已经判断newtable已经存在,则建立newtable1,newtable1存在,则建立newtable2。
以下方法可以得到表的结构!
with query1 do
begin
close;
sql.clear;
sql.add('select * into newtable from 模拟量表');
prepare;
execsql;
close;
sql.clear;
sql.add('delete from newtable');
prepare;
execsql;
end;
能否给我分?谢谢!我们再交流:[email protected]