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


C# DbHelper.ExecuteNoneQuery方法代码示例

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


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

示例1: ModifyReader

        public ResultObject ModifyReader(ReaderInfo readerInfo, bool isdeleted = false)
        {
            ResultObject objRes = new ResultObject();
            objRes.MethodInfo = " ReaderDA.ModifyReader ";

            try
            {
                using (var dbhelper = new DbHelper())
                {
                    // Fetch Reader Group
                    dbhelper.Command.CommandType = System.Data.CommandType.Text;
                    dbhelper.Command.CommandText = "UPDATE [RF].[Reader] " +
                                                   "SET [ReaderGroupID] = @ReaderGroupID " +
                                                    ", [ReaderTypeID] = @ReaderTypeID " +
                                                    ", [ReaderName] = @ReaderName " +
                                                    ", [ReaderDescription] = @ReaderDescription  " +
                                                    ", [IPAddress] = @IPAddress  " +
                                                    ", [PortNo] = @PortNo  " +
                                                    ", [MACAddress] = @MACAddress " +
                                                    ", [AntennaPower] = @AntennaPower " +
                                                    ", [ReaderPower] = @ReaderPower  " +
                                                    ", [LocationRef] = @LocationRef  " +
                                                    ", [LocationDescription] = @LocationDescription  " +
                                                    ", [IsDeleted] = @IsDeleted " +
                                                    ", [UpdateDateTime] = @UpdateDateTime " +
                                                    " WHERE ReaderID = @ReaderID ;";

                    dbhelper.AddParameter("@ReaderGroupID", SqlDbType.Int, readerInfo.ReaderGroupId);
                    dbhelper.AddParameter("@ReaderTypeID", SqlDbType.Int, readerInfo.ReaderTypeId);
                    dbhelper.AddParameter("@ReaderName", SqlDbType.NVarChar, readerInfo.ReaderName);
                    dbhelper.AddParameter("@ReaderDescription", SqlDbType.NVarChar, readerInfo.ReaderDescription);
                    dbhelper.AddParameter("@IPAddress", SqlDbType.NVarChar, readerInfo.IPAddress);
                    dbhelper.AddParameter("@PortNo", SqlDbType.Int, readerInfo.PortNo);
                    dbhelper.AddParameter("@MACAddress", SqlDbType.VarChar, readerInfo.MAC == null ? " " : readerInfo.MAC);
                    dbhelper.AddParameter("@AntennaPower", SqlDbType.VarChar, (float)readerInfo.AntennaPower);
                    dbhelper.AddParameter("@ReaderPower", SqlDbType.Float, readerInfo.AntennaPower);
                    dbhelper.AddParameter("@LocationRef", SqlDbType.NVarChar, readerInfo.LocationRef);
                    dbhelper.AddParameter("@LocationDescription", SqlDbType.NVarChar, readerInfo.LocationDescription);
                    dbhelper.AddParameter("@IsDeleted", SqlDbType.Bit, isdeleted ? 1 : 0);
                    dbhelper.AddParameter("@UpdateDateTime", SqlDbType.DateTime, DateTime.Now);
                    dbhelper.AddParameter("@ReaderID", SqlDbType.Int, readerInfo.ReaderId);

                    int i = dbhelper.ExecuteNoneQuery();

                    objRes.IsSuccess = true;
                    objRes.ResultData["ReaderId"] = readerInfo.ReaderId;
                    //objRes.ResultData["ReaderInfo"] = readerInfo;
                }
            }
            catch (Exception ex)
            {
                objRes.IsSuccess = false;
                objRes.ErrorMessage = "Failed to modify reader into database";
                objRes.ErrorMessageInternal = " Error : " + ex.ToString();
            }

            objRes.TimeStampString = DateTime.Now.ToString();
            return objRes;
        }
开发者ID:Systrics,项目名称:SystricsProjects,代码行数:59,代码来源:ReaderDA.cs

示例2: AddReader

        public ResultObject AddReader(ReaderInfo readerInfo)
        {
            ResultObject objRes = new ResultObject();
            objRes.MethodInfo = " ReaderDA.AddReader ";
            string insertSql =
                                    "INSERT INTO [RF].[Reader] " +
                                                 " ([ReaderGroupID] " +
                                                 ", [ReaderTypeID] " +
                                                 ", [ReaderName] " +
                                                 ", [ReaderDescription] " +
                                                 ", [IPAddress] " +
                                                 ", [PortNo] " +
                                                 ", [MACAddress] " +
                                                 ", [AntennaPower] " +
                                                 ", [ReaderPower] " +
                                                 ", [LocationRef] " +
                                                 ", [LocationDescription] " +
                                                 ", [IsDeleted]  " +
                                                 ", [CreateDateTime]  " +
                                                 ", [UpdateDateTime] ) " +
                                                 " VALUES " +
                                                 "(@ReaderGroupID " +
                                                 ", @ReaderTypeID " +
                                                 ", @ReaderName " +
                                                 ", @ReaderDescription " +
                                                 ", @IPAddress " +
                                                 ", @PortNo " +
                                                 ", @MACAddress " +
                                                 ", @AntennaPower " +
                                                 ", @ReaderPower " +
                                                 ", @LocationRef " +
                                                 ", @LocationDescription " +
                                                 ", @IsDeleted " +
                                                 ", @CreateDateTime " +
                                                 ", @UpdateDateTime ); ";

            try
            {
                using (var dbhelper = new DbHelper())
                {
                    // Fetch Reader Group
                    dbhelper.Command.CommandType = System.Data.CommandType.Text;
                    dbhelper.Command.CommandText = insertSql;

                    dbhelper.AddParameter("@ReaderGroupID", SqlDbType.Int, readerInfo.ReaderGroupId);
                    dbhelper.AddParameter("@ReaderTypeID", SqlDbType.Int, readerInfo.ReaderTypeId);
                    dbhelper.AddParameter("@ReaderName", SqlDbType.NVarChar, readerInfo.ReaderName);
                    dbhelper.AddParameter("@ReaderDescription", SqlDbType.NVarChar, readerInfo.ReaderDescription);
                    dbhelper.AddParameter("@IPAddress", SqlDbType.NVarChar, readerInfo.IPAddress);
                    dbhelper.AddParameter("@PortNo", SqlDbType.Int, readerInfo.PortNo);
                    dbhelper.AddParameter("@MACAddress", SqlDbType.VarChar, readerInfo.MAC == null ? "  " : readerInfo.MAC);
                    dbhelper.AddParameter("@AntennaPower", SqlDbType.VarChar, (float)readerInfo.AntennaPower);
                    dbhelper.AddParameter("@ReaderPower", SqlDbType.Float, (float)1.0); // readerInfo.AntennaPower);
                    dbhelper.AddParameter("@LocationRef", SqlDbType.NVarChar, readerInfo.LocationRef);
                    dbhelper.AddParameter("@LocationDescription", SqlDbType.NVarChar, readerInfo.LocationDescription);
                    dbhelper.AddParameter("@IsDeleted", SqlDbType.Bit, 0);
                    dbhelper.AddParameter("@CreateDateTime", SqlDbType.DateTime, DateTime.Now);
                    dbhelper.AddParameter("@UpdateDateTime", SqlDbType.DateTime, DateTime.Now);

                    int i = dbhelper.ExecuteNoneQuery();

                    objRes.IsSuccess = true;
                }
            }
            catch (Exception ex)
            {
                objRes.IsSuccess = false;
                objRes.ErrorMessage = "Failed to add reader into database";
                objRes.ErrorMessageInternal = " Error : " + ex.ToString();
            }

            //try to return readerId for newly added reader
            ResultObject internalResultObject = new ResultObject();
            internalResultObject = GetReaderByReaderName(readerInfo.ReaderName);

            //Assign readerId to main result object with key "ReaderId"
            objRes.ResultData["ReaderId"] = internalResultObject.IsSuccess ? ((ReaderInfo)internalResultObject.ResultData["ReaderInfo"]).ReaderId : -1 /*OnError reader is -1*/;
               readerInfo.ReaderId  = internalResultObject.IsSuccess ? ((ReaderInfo)internalResultObject.ResultData["ReaderInfo"]).ReaderId : -1 /*OnError reader is -1*/;
            objRes.ResultData["ReaderInsertSql"] = insertSql;
            objRes.TimeStampString = DateTime.Now.ToString();

            return objRes;
        }
开发者ID:Systrics,项目名称:SystricsProjects,代码行数:83,代码来源:ReaderDA.cs

示例3: ExeSP

        public ResultObject ExeSP(int readerId, string tagIds)
        {
            ResultObject objRes = new ResultObject();
            objRes.MethodInfo = "ReaderDA.ExeSP ";

            string spName = "[RF].[spProcessTags]";
            try
            {
                using (var dbhelper = new DbHelper())
                {
                    dbhelper.Command.CommandType = System.Data.CommandType.StoredProcedure;
                    dbhelper.Command.CommandText = spName;
                    dbhelper.AddParameter("@ReaderId", SqlDbType.VarChar, readerId);
                    dbhelper.AddParameter("@tags", SqlDbType.VarChar, tagIds);

                    dbhelper.ExecuteNoneQuery();
                }

                objRes.IsSuccess = true;
            }
            catch (Exception ex)
            {
                objRes.IsSuccess = false;
                objRes.ErrorMessage = "Failed to execute sp for processing tags.";
                objRes.ErrorMessageInternal = "Error : " + ex.ToString();
            }

            objRes.TimeStampString = DateTime.Now.ToString();
            return objRes;
        }
开发者ID:Systrics,项目名称:SystricsProjects,代码行数:30,代码来源:ReaderDA.cs


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