当前位置: 首页>>代码示例>>C#>>正文


C# DbCommand.ExecuteScalar方法代码示例

本文整理汇总了C#中DbCommand.ExecuteScalar方法的典型用法代码示例。如果您正苦于以下问题:C# DbCommand.ExecuteScalar方法的具体用法?C# DbCommand.ExecuteScalar怎么用?C# DbCommand.ExecuteScalar使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DbCommand的用法示例。


在下文中一共展示了DbCommand.ExecuteScalar方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetForumBreadCrumbs

        public static string GetForumBreadCrumbs(int forumID, DbCommand cmd)
        {
            string retval = "";

            //to save performance and prevent close/reopn connection a thousand times we do this
            bool openConn = (cmd.Connection.State == ConnectionState.Open);
            if (!openConn) cmd.Connection.Open();

            //get the forum title
            cmd.CommandText = "SELECT Title FROM Forums WHERE ForumID=" + forumID;
            string forumTitle = cmd.ExecuteScalar().ToString();

            retval = "<a href=\"" + GetForumURL(forumID, forumTitle) + "\">" + forumTitle + "</a>";

            //check if it's a subforum
            cmd.CommandText = "SELECT ParentForumID FROM ForumSubforums WHERE SubForumID=" + forumID;
            object res = cmd.ExecuteScalar();
            if (res != null) retval = GetForumBreadCrumbs(Convert.ToInt32(res), cmd) + " - " + retval;

            if (!openConn) cmd.Connection.Close();

            return retval;
        }
开发者ID:VirtusStudio,项目名称:Tri-Living-Well,代码行数:23,代码来源:aspnetforum.cs

示例2: ExecuteScalar

 public override object ExecuteScalar(DbCommand command)
 {
     if (_Connection.State != System.Data.ConnectionState.Open) _Connection.Open();
     command.Connection = _Connection;
     command.Transaction = _Transaction;
     return command.ExecuteScalar();
 }
开发者ID:danielgindi,项目名称:dg.Sql,代码行数:7,代码来源:MySqlConnector.cs

示例3: Count

        //Count statement
        public int Count(DbCommand query)
        {
            int Count = -1;

            //Open Connection
            if (this.OpenConnection() != null)
            {
                //Create Mysql Command
                query.Connection = connection;

                //ExecuteScalar will return one value
                Count            = int.Parse(query.ExecuteScalar() + "");

                //close Connection
                this.CloseConnection();

                return Count;
            }
            else
            {
                return Count;
            }
        }
开发者ID:nkasozi,项目名称:Nkujukira,代码行数:24,代码来源:MySQLDataBaseHandler.cs


注:本文中的DbCommand.ExecuteScalar方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。