教程中国
PHOTOSHOP CS9.0中文版 MAYA 8.5 FOR WINDOWS Corel Painter v9.0 Flash MX2004 中文版 Illustrator cs2 中文版
VC++6.0含sp6 中英文版 VB6.0 +sp6 简体中文版 Borland Delphi 7汉化版 MSDN for vb6.0中文版 Visual Studio 2005简体
教程中国下属 文件存储共享专家BIBIDU.COM 提供大型软件,教材,源码,电影,音乐,图书等下载 更多精品请点此进入
  您目前所在位置: 教程中国 >> .NET类 >> ASP.NET >> Counting Records in an SQL Table by G.F. Weis Gfw RSS订阅
Counting Records in an SQL Table by G.F. Weis Gfw
教程(视频,书籍)下载:  ASP.NET AutoCAD 数据库 C# ASP java photoshop 网页设计 delphi 3dmax Flash C++ VB 张孝祥 实例   更多请进入BIBIDU搜索
IT搜索引擎   
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


来源:upschool.com.cn
作者:
关键字:Counting,Records,in,an,SQL,Table,by,G.F.,Weis,Gfw
发表日期:2005-12-23

网页显示有限 阅读全文请下载本文完整版WORD文档

上一篇:BETA2中操作SQL数据库   下一篇:DataSet的几个基本操作


本文的相类似文章
  • Photoshop手绘超完美《Handgun》
  • Photoshop打造逼真WALKMAN播放器
  • 用SkinTune给你的MM美美容
  • .NET框架下Oracle到SQL Server迁移
  • 实现400节点大中型企业VLAN方案
  • D-Link无线ADSL宽带接入解决方案
  • Internet防火墙的应用技术综述
  • Win 2000平台架设Tomcat教程
  • 给DHCP设浮桥 多Vlan自动分配IP
  • Linux下双网卡绑定实现负载均衡
  • 网友评论 查看本文全部评论
    笔 名: *
    评 论:
    最多500字。当前字数:0
    联系方式:
    验证码:
    在学习中进步 在进步中成长 教程中国相随您的成长之路
    华腾联合科技股份有限公司版权所有
    广告联系:Rosibo@163.com