国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > 綜合 > 正文

counting Records in an SQL Table by G.F. Weis Gfw

2024-07-21 02:23:47
字體:
供稿:網(wǎng)友
counting records in an  sql table by g.f. weis gfw


--------------------------------------------------------------------------------

i was working on a project using my c# class generator  and realized that i had no way to get a count of the number of records in the table. in the past i have used the dataadapter class - easy, but not very efficient.

i ran accross a post on one of the discussion forums and decided to build a new function in my class generator appropriately named recordcount. the function returns an 'int' with the number of records in the table.

m_dbconnection is the connection string to your database
arepresentative is the name of our table
id is unique column used in our table
using the c# class generator, the generated code is as follows:


public int recordcount() // get count of records
{
    int reccount=0;
    string countcmd = "select count(id) as total from arepresentative ";
    sqlconnection m_sqlconnection = new sqlconnection(m_dbconnection);
    sqlcommand    m_sqlcommand    = new sqlcommand(countcmd, m_sqlconnection);
    try
    {
        // open the connection ----------------------------
        m_sqlcommand.connection.open();
        reccount = (int)m_sqlcommand.executescalar();
    } // end try
    catch (exception e)
    {
        throw new exception("error in recordcount() -> " + e.tostring());
    }
    finally
    {
        m_sqlconnection.close();
        m_sqlcommand.dispose();
    }
    return reccount;
} // end select
發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 韩城市| 随州市| 濮阳市| 尚义县| 浦东新区| 牡丹江市| 孝昌县| 台中县| 黎城县| 平塘县| 新邵县| 炎陵县| 阳春市| 莱阳市| 富川| 明星| 舞阳县| 南溪县| 武山县| 营口市| 紫金县| 遂平县| 金沙县| 绥江县| 安宁市| 商水县| 长岭县| 开原市| 开远市| 北海市| 含山县| 吕梁市| 泸水县| 平定县| 兴业县| 平乡县| 平乡县| 阿图什市| SHOW| 永年县| 阿图什市|