本文整理汇总了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;
}
示例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;
}
示例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;
}