Try
Database1.Connected:=True;
except
showmessage('数据库错误');
end; Try
Begin
table1.Close;
table1.TableName:=数据表名;
table1.Open;
end
except
showmessage('表不存在');
end;
Database1.Connected:=True;
except
showmessage('数据库错误');
end; Try
Begin
table1.Close;
table1.TableName:=数据表名;
table1.Open;
end
except
showmessage('表不存在');
end;
sSqlServer可以这样判断:
LSql := 'select name from sysobject
where Name in (''TableName1'',''TableName1'',''TableName1''...) and type = ''U'' '
如果查询结果为空,则没有
如:SQL_SERVER的SYSOBJECTS和ORACLE的ALL_TABLES等。看你用什么数据库。
你能帮我详解一下吗???
我的数据库是SQL server
Database.Connected:=True; 一个TQUERY
query.sql.clear;
query.Sql.Add('select * from sysdatabases where name=''数据库名''');
query.Open;
if query.Recordcount>0 then showmessage('database exists');query.sql.clear
query.sql.add('select * from sysobjects where name in (''表名'',...) and type='U');
query.open;
Session.GetAlias()
Session.GetTablenames()
query1.sql.add('select * from sysobjects where name in ("operator") and type="U"');
捡查时错,能帮我看看吗???Porject b.exe raised exception class EDBEngineError with message 'Invalid field name.
[Microsoft][ODBC SQL Server Driver][SQL server]Invalid column name 'oper'.
[Microsoft][ODBC SQL Server Driver][SQL server]Invalid column name 'U'.. Process stopped. use step or run to continue.有没有解决方法???
就可以判断一个数据库在不在啦,其它的事就好办了。:)祝你好运
Try
DateBaseType :=Session.GetAliasDriverName('数据库名称');
Except
MessageDlg('请检查是否配置数据库',mtError,[mbOK],0);
Exit;
End; Try
Database1.Connected:=True;
Except
On E: Exception do
Begin
MessageDlg('失败!+E.Message,MtError,[mbOK],0);
Exit;
End
End;其他和顶楼的一样,不这些代码扩充以下,就行了
检查帮助中的TSession。
写错了在表名上不能使用双引号”,只能用单的。
不然在delphi上无法通过