How to check if my table is empty from C#?
I have something like:
x
public MySqlConnection con;
public MySqlCommand cmd;
con = new MySqlConnection(GetConnectionString());
con.Open();
cmd = new MySqlCommand("SELECT * FROM data;", con);
Or I don’t need to call SELECT statement?
Advertisement
Answer
You can use COUNT(*)
with no WHERE
close and see if exactly how many rows exist with the result.
Or you can do a SELECT (id) FROM tablename
with no WHERE
clause and if no rows are returned then the table is empty.