Note that there are some explanatory texts on larger screens.

plurals
  1. POCheck if a table is empty (MSAccess Database + Delphi)
    primarykey
    data
    text
    <p>I need to findout whether a created table has entries in it or not.</p> <p>What I need is, </p> <pre><code>if (TableIsEmpty) then do_something else do_something_else; </code></pre> <p>What I've written for the purpose is :</p> <pre><code>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; </code></pre> <p>But this function returns true irrespective of status of the table!</p> <p><em><strong></em> EDIT***</strong> Modified Code : </p> <pre><code>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 &lt;= 0 then result := true else result := false; Form2.ADOConnection1.Close; End; </code></pre> <p>This function always returns false!!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload