gpt4 book ai didi

database - 检查表是否为空(MSAccess 数据库 + Delphi)

转载 作者:搜寻专家 更新时间:2023-10-30 19:41:32 28 4
gpt4 key购买 nike

我需要查明创建的表中是否有条目。

我需要的是,

if (TableIsEmpty) then
do_something
else
do_something_else;

我为此写的是:

Function IsTableEmpty:Boolean;
Var
DataSource : string;
Begin
DataSource :=
'Provider=Microsoft.Jet.OLEDB.4.0'+
';Data Source=c:\mydb.mdb'+
';Persist Security Info=False';

Form2.ADOConnection1.ConnectionString := DataSource;
Form2.ADOConnection1.LoginPrompt := False;
Form2.ADOCommand1.Connection := Form2.ADOConnection1;
Form2.ADOTable1.ConnectionString := DataSource;
Form2.ADOTable1.Connection := Form2.ADOConnection1;
if (Form2.ADOTable1.IsEmpty)then
result := true
else
result := false;
End;

但是无论表的状态如何,这个函数都会返回 true!

编辑***修改代码:

Function IsTableEmpty:Boolean;
Var
DataSource, cs : string;
Begin
DataSource :=
'Provider=Microsoft.Jet.OLEDB.4.0'+
';Data Source=c:\Users.mdb'+
';Persist Security Info=False';

Form2.ADOConnection1.ConnectionString := DataSource;
Form2.ADOConnection1.LoginPrompt := False;
Form2.ADOCommand1.Connection := Form2.ADOConnection1;
Form2.ADOTable1.Connection := Form2.ADOConnection1;
Form2.ADOTable1.TableName := 'userIdentification';
Form2.ADOTable1.Active := True;
cs := 'Select * from userIdentification';
Form2.ADOCommand1.CommandText := cs;
Form2.ADOCommand1.Execute;
if Form2.ADOTable1.RecordCount <= 0 then
result := true
else
result := false;
Form2.ADOConnection1.Close;
End;

这个函数总是返回 false!!

最佳答案

if Form2.ADOTable1.RecordCount =< 0 then
do_something
else
do_something_else;

在成功执行 select 语句后运行此命令

关于database - 检查表是否为空(MSAccess 数据库 + Delphi),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19354219/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com