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


C# SqlQuery.ExecuteScalar方法代码示例

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


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

示例1: GetDatabaseVersion

 /// <summary>
 /// 数据库版本号信息
 /// </summary>
 public override string GetDatabaseVersion()
 {
     using (SqlQuery query = new SqlQuery())
     {
         query.CommandText = "SELECT @@VERSION;";
         return query.ExecuteScalar<string>();
     }
 }
开发者ID:huchao007,项目名称:bbsmax,代码行数:11,代码来源:DatabaseInfoDao.cs

示例2: GetDatabaseTimeDifference

 /// <summary>
 /// 获取数据库时间和标准时间的时差(秒)
 /// </summary>
 /// <returns></returns>
 public override int GetDatabaseTimeDifference()
 {
     using (SqlQuery query = new SqlQuery())
     {
         query.CommandText = "SELECT DATEDIFF(minute,GETUTCDATE(),GETDATE())";
         return query.ExecuteScalar<int>();
     }
 }
开发者ID:huchao007,项目名称:bbsmax,代码行数:12,代码来源:DatabaseInfoDao.cs

示例3: ExistsBlogArticle

        public override bool ExistsBlogArticle(int articleID)
        {
            using (SqlQuery db = new SqlQuery())
            {
                db.CommandText = "bx_Blog_ExistsBlogArticle";
                db.CommandType = CommandType.StoredProcedure;

                db.CreateParameter<int>("@ArticleID", articleID, SqlDbType.Int);

                return db.ExecuteScalar<bool>();
            }
        }
开发者ID:huchao007,项目名称:bbsmax,代码行数:12,代码来源:BlogDao.cs

示例4: GetTodayPostDoingCount

        public override int GetTodayPostDoingCount(int userID, DateTime today)
        {
            using (SqlQuery db = new SqlQuery())
            {
                db.CommandText = "bx_Doing_GetTodayPostDoingCount";
                db.CommandType = CommandType.StoredProcedure;

                db.CreateParameter<int>("@UserID", userID, SqlDbType.Int);
                db.CreateParameter<DateTime>("@Today", today, SqlDbType.DateTime);

                return db.ExecuteScalar<int>();
            }
        }
开发者ID:huchao007,项目名称:bbsmax,代码行数:13,代码来源:DoingDao.cs

示例5: GetPostBlogArticleCount

        public override int GetPostBlogArticleCount(int userID, DateTime beginDate, DateTime endDate)
        {
            using (SqlQuery db = new SqlQuery())
            {
                db.CommandText = "bx_Blog_GetPostBlogArticleCount";
                db.CommandType = CommandType.StoredProcedure;

                db.CreateParameter<int>("@UserID", userID, SqlDbType.Int);
                db.CreateParameter<DateTime>("@BeginDate", beginDate, SqlDbType.DateTime);
                db.CreateParameter<DateTime>("@EndDate", endDate, SqlDbType.DateTime);

                return db.ExecuteScalar<int>();
            }
        }
开发者ID:huchao007,项目名称:bbsmax,代码行数:14,代码来源:BlogDao.cs

示例6: IsValidClick

        public override bool IsValidClick(string userOrGuestID, int targetId, string Ip, ClickSourceType type, int availibleUserInterval, DateTime AllowIpLastClickDateTime, int availibleIpClickCount)
        {
            using (SqlQuery query = new SqlQuery())
            {
                query.CommandText = "bx_IsAvailibleClick";
                query.CommandType = System.Data.CommandType.StoredProcedure;
                query.CreateParameter<string>("@Ip", Ip, SqlDbType.VarChar, 50);
                query.CreateParameter<string>("@UserIdentify", userOrGuestID, SqlDbType.VarChar, 200);
                query.CreateParameter<DateTime>("@AllowUserLastClickDateTime", DateTimeUtil.Now.AddSeconds(-availibleUserInterval), SqlDbType.DateTime);
                query.CreateParameter<DateTime>("@AllowIpLastClickDateTime", AllowIpLastClickDateTime, SqlDbType.DateTime);
                query.CreateParameter<int>("@AllowIpTotalClicks", availibleIpClickCount, SqlDbType.Int);
                query.CreateParameter<int>("@SourceType", (int)type, SqlDbType.Int);
                query.CreateParameter<int>("@TargetID", targetId, SqlDbType.Int);

                return (int)query.ExecuteScalar() == 1;
            }
        }
开发者ID:huchao007,项目名称:bbsmax,代码行数:17,代码来源:ClickLogDao.cs

示例7: CheckOverFlowBuyCount

        public override bool CheckOverFlowBuyCount(int userID, InviteBuyInterval interval, int canBuyCount)
        {

            if (interval == InviteBuyInterval.Disable) return false;

            using (SqlQuery query = new SqlQuery())
            {
                DateTime beginTime = DateTimeUtil.Now, endTime = DateTimeUtil.Now;

                switch (interval)
                {
                    case InviteBuyInterval.ByDay:
                        beginTime = DateTimeUtil.Now.AddDays(-1);
                        break;
                    case InviteBuyInterval.ByHour:
                        beginTime = DateTimeUtil.Now.AddHours(-1);
                        break;
                    case InviteBuyInterval.ByMonth:
                        beginTime = DateTimeUtil.Now.AddMonths(-1);
                        break;
                    case InviteBuyInterval.ByYear:
                        beginTime = DateTimeUtil.Now.AddYears(-1);
                        break;
                }

                query.CreateParameter<int>("@UserID", userID, SqlDbType.Int);
                query.CreateParameter<DateTime>("@BeginTime", beginTime, SqlDbType.DateTime);
                query.CreateParameter<DateTime>("@EndTime", endTime, SqlDbType.DateTime);
                query.CreateParameter<int>("@BuyCount", canBuyCount, SqlDbType.Int);

                query.CommandText = "bx_CheckOverFlowBuyCount";
                query.CommandType = CommandType.StoredProcedure;

                object result = null;
                result = query.ExecuteScalar();

                if (result == null) return false;

                if (Convert.ToInt32(result) == 0)
                    return false;
                else
                    return true;
            }
        }
开发者ID:huchao007,项目名称:bbsmax,代码行数:44,代码来源:InviteDao.cs

示例8: CreateAlbum

        public override int CreateAlbum(int userID, PrivacyType privacyType, string name, string description, string cover, string password)
        {
            using (SqlQuery query = new SqlQuery())
            {
                query.CommandText = "bx_Album_CreateAlbum";
                query.CommandType = CommandType.StoredProcedure;


                query.CreateParameter<int>("@UserID", userID, SqlDbType.Int);
                query.CreateParameter<PrivacyType>("@PrivacyType", privacyType, SqlDbType.TinyInt);
                query.CreateParameter<string>("@Name", name, SqlDbType.NVarChar, 50);
                query.CreateParameter<string>("@Description", description, SqlDbType.NVarChar, 100);
                query.CreateParameter<string>("@Cover", cover, SqlDbType.NVarChar, 200);
                query.CreateParameter<string>("@Password", password, SqlDbType.NVarChar, 50);


                return query.ExecuteScalar<int>();
            }
        }
开发者ID:huchao007,项目名称:bbsmax,代码行数:19,代码来源:AlbumDao.cs

示例9: GetTimeIntervalFromDatabase

        /// <summary>
        /// 获取系统启动时数据库当前时间与程序时间的相差毫秒数
        /// </summary>
        public override double GetTimeIntervalFromDatabase()
        {
            using (SqlSession session = new SqlSession())
            {
                string connectionString = session.Connection.ConnectionString;

                Regex regexConnString1 = new Regex(@"^.*\s?(?>Server|Data\s+Source)\s*=\s*(?>\.|\(local\)|127\.0\.0\.1|localhost|::1)\s*;.*?", RegexOptions.IgnoreCase);

                if (regexConnString1.IsMatch(connectionString))
                {
                    return 0.0f;
                }

                using (SqlQuery query = new SqlQuery())
                {
                    query.CommandText = "SELECT GETDATE();";
                    return (query.ExecuteScalar<DateTime>() - DateTimeUtil.Now).TotalMilliseconds;
                }
            }
        }
开发者ID:huchao007,项目名称:bbsmax,代码行数:23,代码来源:DatabaseInfoDao.cs

示例10: DeleteComment

        public override void DeleteComment(int userID, int commentID, out int commentUserID)
        {
            using (SqlQuery query = new SqlQuery())
            {
                query.CommandText = @"SELECT TargetUserID FROM bx_Comments WHERE (UserID = @UserID OR TargetUserID = @UserID) AND CommentID = @CommentID;
                                      DELETE FROM bx_Comments WHERE (UserID = @UserID OR TargetUserID = @UserID) AND CommentID = @CommentID";

                query.CreateParameter<int>("@CommentID", commentID, SqlDbType.Int);
                query.CreateParameter<int>("@UserID", userID, SqlDbType.Int);

                commentUserID = query.ExecuteScalar<int>();
            }
        }
开发者ID:huchao007,项目名称:bbsmax,代码行数:13,代码来源:CommentDao.cs

示例11: UpdateComment

        public override void UpdateComment(int commentID, int operatorUserID, bool isApproved, string content, string contentReverter, out int targetID)
        {
            targetID = 0;
            string sql = @"SELECT TargetID FROM bx_Comments WHERE CommentID = @CommentID;
                           UPDATE bx_Comments SET Content = @Content, IsApproved = @IsApproved, KeywordVersion = '', LastEditUserID = @OperatorUserID WHERE CommentID = @CommentID;";

            using (SqlQuery query = new SqlQuery())
            {
                query.CommandText = sql;

                query.CreateParameter<int>("@CommentID", commentID, SqlDbType.Int);
                query.CreateParameter<int>("@OperatorUserID", operatorUserID, SqlDbType.Int);
                query.CreateParameter<bool>("@IsApproved", isApproved, SqlDbType.Bit);
                query.CreateParameter<string>("@Content", content, SqlDbType.NVarChar, 3000);
                query.CreateParameter<string>("@ContentReverter", contentReverter, SqlDbType.NVarChar, 1000);

                targetID = query.ExecuteScalar<int>();
            }
        }
开发者ID:huchao007,项目名称:bbsmax,代码行数:19,代码来源:CommentDao.cs

示例12: CreateImpression

        public override bool CreateImpression(int userID, int targetUserID, string text, int timeLimit)
        {
            using (SqlQuery db = new SqlQuery())
            {
                db.CommandText = "bx_Impression_Create";
                db.CommandType = System.Data.CommandType.StoredProcedure;

                db.CreateParameter<int>("@UserID", userID, System.Data.SqlDbType.Int);
                db.CreateParameter<int>("@TargetUserID", targetUserID, System.Data.SqlDbType.Int);
                db.CreateParameter<string>("@Text", text, System.Data.SqlDbType.NVarChar, 100);
                db.CreateParameter<int>("@TimeLimit", timeLimit, System.Data.SqlDbType.Int);

                return db.ExecuteScalar<int>() == 1;
            }
        }
开发者ID:huchao007,项目名称:bbsmax,代码行数:15,代码来源:ImpressionDao.cs

示例13: GetThreadCount

        public override int GetThreadCount(int forumID, DateTime? beginDate, DateTime? endDate, bool includeStick)
        {
            using (SqlQuery query = new SqlQuery())
            {
                query.CommandText = "bx_GetThreadCount";
                query.CommandType = CommandType.StoredProcedure;

                query.CreateParameter<int>("@ForumID", forumID, SqlDbType.Int);
                query.CreateParameter<bool>("@IncludeStick", includeStick, SqlDbType.Bit);
                query.CreateParameter<DateTime?>("@BeginDate", beginDate, SqlDbType.DateTime);
                query.CreateParameter<DateTime?>("@EndDate", endDate, SqlDbType.DateTime);

                return query.ExecuteScalar<int>();
            }
        }
开发者ID:huchao007,项目名称:bbsmax,代码行数:15,代码来源:PostDao.cs

示例14: WriteInstruct

 /// <summary>
 /// 指令写入数据库
 /// </summary>
 /// <param name="userID"></param>
 /// <param name="clientID"></param>
 /// <param name="type"></param>
 /// <param name="createDate"></param>
 /// <param name="datas"></param>
 /// <returns></returns>
 public override long WriteInstruct(int targetID, int clientID, MaxLabs.bbsMax.Enums.InstructType type, DateTime createDate, string datas)
 {
     using( SqlQuery query=new SqlQuery())
     {
         query.CommandText = "INSERT INTO bx_Instructs( ClientID, TargetID, InstructType, CreateDate, Datas) VALUES( @ClientID, @TargetID, @InstructType, @CreateDate, @Datas); SELECT @@IDENTITY;";
         query.CommandType = System.Data.CommandType.Text;
         query.CreateParameter<int>("@ClientID", clientID, SqlDbType.Int);
         query.CreateParameter<int>("@TargetID", targetID, SqlDbType.Int);
         query.CreateParameter<int>("@InstructType", (int)type, SqlDbType.Int);
         query.CreateParameter<DateTime>("@CreateDate", createDate, SqlDbType.DateTime);
         query.CreateParameter<string>("@Datas", datas, SqlDbType.NText);
         return  query.ExecuteScalar<long>();
     }
 }
开发者ID:huchao007,项目名称:bbsmax,代码行数:23,代码来源:PassportDao.cs

示例15: GetClubMemberStatus

        public override ClubMemberStatus? GetClubMemberStatus(int clubID, int userID)
        {
            using (SqlQuery db = new SqlQuery())
            {
                db.CommandText = "bx_Club_GetClubMemberStatus";
                db.CommandType = CommandType.StoredProcedure;

                db.CreateParameter<int>("@ClubID", clubID, SqlDbType.Int);
                db.CreateParameter<int>("@UserID", userID, SqlDbType.Int);

                byte? result = db.ExecuteScalar<byte?>();

                if (result == null)
                    return null;

                return (ClubMemberStatus)result.Value;
            }
        }
开发者ID:huchao007,项目名称:bbsmax,代码行数:18,代码来源:ClubDao.cs


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