c# - Simple way to check how many rows I have in my database -


i'm connected database through sqlconnection class. there simple why check how many rows in database or have create sqldatareader , increment till last row in ?

i assume "rows in database" means "rows in table".

you should use count , sqlcommand.executescalar:

int rowcount = 0; using(var con = new sqlconnection(connectionsstring)) using (var cmd = new sqlcommand("select count(*) dbo.tablename", con)) {     try     {         con.open();         rowcount = (int) cmd.executescalar();     } catch (exception ex)     {          // log exception or else useful, otherwise it's better to...         throw;     } } 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -