本文整理汇总了C#中IDbHelper.ExecuteScalar方法的典型用法代码示例。如果您正苦于以下问题:C# IDbHelper.ExecuteScalar方法的具体用法?C# IDbHelper.ExecuteScalar怎么用?C# IDbHelper.ExecuteScalar使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDbHelper
的用法示例。
在下文中一共展示了IDbHelper.ExecuteScalar方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetProperty
/// <summary>
/// 读取属性
/// </summary>
/// <param name="dbHelper">数据库连接</param>
/// <param name="tableName">目标表名</param>
/// <param name="parameters">字段名,键值</param>
/// <param name="targetField">获取字段</param>
/// <returns>属性</returns>
public static string GetProperty(IDbHelper dbHelper, string tableName, List<KeyValuePair<string, object>> parameters, string targetField)
{
string returnValue = string.Empty;
string sqlQuery = " SELECT " + targetField
+ " FROM " + tableName
+ " WHERE " + GetWhereString(dbHelper, parameters, BaseBusinessLogic.SQLLogicConditional);
object returnObject = dbHelper.ExecuteScalar(sqlQuery, dbHelper.MakeParameters(parameters));
if (returnObject != null)
{
returnValue = returnObject.ToString();
}
return returnValue;
}
示例2: GetCount
/// <summary>
/// 获取个数
/// </summary>
/// <param name="dbHelper">数据库连接</param>
/// <param name="tableName">目标表名</param>
/// <param name="parameters">目标字段,值</param>
/// <returns>行数</returns>
public static int GetCount(IDbHelper dbHelper, string tableName, List<KeyValuePair<string, object>> parameters, KeyValuePair<string, object> parameter = new KeyValuePair<string, object>())
{
int returnValue = 0;
string sqlQuery = " SELECT COUNT(1) "
+ " FROM " + tableName
+ " WHERE " + GetWhereString(dbHelper, parameters, BaseBusinessLogic.SQLLogicConditional);
if (!string.IsNullOrEmpty(parameter.Key))
{
switch (DbHelper.DbType)
{
case DbTypes.Access:
// BaseSequence表的ID 是字符类型
if (tableName == "BaseSequence")
sqlQuery += BaseBusinessLogic.SQLLogicConditional + "( " + parameter.Key + " <> '" + parameter.Value + "' ) ";
else if (parameter.Value == null)
sqlQuery += BaseBusinessLogic.SQLLogicConditional + "( " + parameter.Key + " <> 0 ) ";
else
sqlQuery += BaseBusinessLogic.SQLLogicConditional + "( " + parameter.Key + " <> " + parameter.Value + " ) ";
break ;
default :
sqlQuery += BaseBusinessLogic.SQLLogicConditional + "( " + parameter.Key + " <> '" + parameter.Value + "' ) ";
break ;
}
}
object returnObject = null;
if (parameters != null)
{
returnObject = dbHelper.ExecuteScalar(sqlQuery, dbHelper.MakeParameters(parameters));
}
else
{
returnObject = dbHelper.ExecuteScalar(sqlQuery);
}
if (returnObject != null)
{
returnValue = int.Parse(returnObject.ToString());
}
return returnValue;
}
示例3: GetCategoryCount
/// <summary>
/// 获得某部门某种属性的人数
/// </summary>
/// <param name="categoryId"></param>
/// <param name="organizeCode"></param>
/// <param name="categoryField"></param>
/// <returns></returns>
public string GetCategoryCount(IDbHelper dbHelper, string categoryId, string organizeCode, string categoryField)
{
String sqlQuery = string.Empty;
string staffCount = string.Empty;
string[] names = new string[3];
object[] values = new object[3];
sqlQuery = " SELECT COUNT(Id) AS STAFFCOUNT FROM " + BaseStaffEntity.TableName
+ " WHERE (" + categoryField + " = ?) AND (ENABLED = 1) AND (ISDIMISSION <> 1) AND (ISSTAFF = 1) AND (DepartmentId IN (SELECT Id FROM " + BaseOrganizeEntity.TableName + " WHERE (LEFT(CODE, LEN(?)) = ?))) ";
names[0] = categoryField;
names[1] = BaseOrganizeEntity.FieldCode;
names[2] = organizeCode;
values[0] = categoryId;
values[1] = organizeCode;
values[2] = organizeCode;
object returnValue = dbHelper.ExecuteScalar(sqlQuery, DbHelper.MakeParameters(names, values));
if (returnValue != null)
{
staffCount = returnValue.ToString();
}
return staffCount;
}
示例4: GetParentIdByCode
/// <summary>
/// 获取父节点
/// </summary>
/// <param name="tableName">目标表名</param>
/// <param name="fieldCode">编码字段</param>
/// <param name="code">编号</param>
/// <returns>主键</returns>
public static string GetParentIdByCode(IDbHelper dbHelper, string tableName, string fieldCode, string code)
{
string parentId = string.Empty;
string sqlQuery = " SELECT MAX(Id) AS Id "
+ " FROM " + tableName
+ " WHERE (LEFT(" + dbHelper.GetParameter(fieldCode) + ", LEN(" + fieldCode + ")) = " + fieldCode + ") "
+ " AND " + fieldCode + " <> '" + code + " ' ";
string[] names = new string[1];
Object[] values = new Object[1];
names[0] = fieldCode;
values[0] = code;
object returnObject = dbHelper.ExecuteScalar(sqlQuery, dbHelper.MakeParameters(names, values));
if (returnObject != null)
{
parentId = returnObject.ToString();
}
return parentId;
}