C# Sql Select Count Tutorial MS Access OleDb
In this C# tutorial, we will select count the number of records of users table from MS Access (.mdb) database file using C# code sample below.
C# SQL Select Count Code
using System.Data;
using System.Data.OleDb;
public DataSet GetUserCount()
{
string constr =
"Provider=Data Source=yourmdbfile.mdb;provider=Microsoft.Jet.OLEDB.4.0";
string str_select = "SELECT COUNT(*) FROM tbl_users";
OleDbConnection con = new OleDbConnection(constr);
DataSet ds = new DataSet();
OleDbDataAdapter da = new OleDbDataAdapter(str_select, con);
da.Fill(ds);
return ds;
}
Note that you can also use this code sample in ASP.NET.