c# - Store in a variable the number of rows from a table where a column has a certain value in SQL Server Compact -
i have windows forms application , sql server compact 3.5 database. want store in variable number of rows table column has value. have count rows table:
carsdataset carsdata = new carsdataset(); int nrcars = carsdata.carname.rows.count;
how can information need?
first you'll want write sql command returns number of rows in query (using count(*) operator). clause of sql statement can filter specific cars want (e.g. model = 'ford')
string sql = "select count(*) cars somecolumn='{put_your_filter_here}'";
now create sqlcommand object execute on sqlceconnection. you'll need open sqlceconnection local sql compact edition database.
sqlcecommand cmd = new sqlcecommand(sql, dbconnection.ceconnection);
execute command returns count(*) number of rows , stores in cars variable
int cars = (int)cmd.executescalar();
use/print result of query
console.writeline("number of cars: " + cars);
Comments
Post a Comment