关闭

某君的部分SqlHelper

标签: parametersdatasetstringtablenullup
548人阅读 评论(0) 收藏 举报
分类:
///
 
<summary>

/// 向数据集表中添加一行
/// </summary>
public void fnAddRow(System.Data.DataTable table, Sn.Model.KuCun.clstemp model, bool AcceptChanged)
{
System.Data.DataRow dr
= table.NewRow();
if (model != null )
{
dr[
" id " ] = model.id;
dr[
" name " ] = model.name;
table.Rows.Add(dr);
if (AcceptChanged)
{
table.AcceptChanges();
}
}
}

/// <summary>
/// 更新表中的一行
/// </summary>
public void fnSetRow(System.Data.DataRow dr, Sn.Model.KuCun.clstemp model)
{
if (model != null )
{
dr[
" id " ] = model.id;
dr[
" name " ] = model.name;
}
}

/// <summary>
/// 获得数据列表
/// </summary>
public DataSet GetList( string strWhere)
{
StringBuilder strSql
= new StringBuilder();
strSql.Append(
" select id,name " );
strSql.Append(
" FROM temp with(nolock) " );
if (strWhere.Trim() != "" )
{
strSql.Append(
" where " + strWhere);
}
return DbHelperSQL.Query(strSql.ToString());
}
/// <summary>
/// 获得数据列表
/// </summary>
public DataSet GetList( string strWhere, string strselect)
{
StringBuilder strSql
= new StringBuilder();
strSql.Append(
" select " + strselect);
strSql.Append(
" FROM temp with(nolock) " );
if (strWhere.Trim() != "" )
{
strSql.Append(
" where " + strWhere);
}
return DbHelperSQL.Query(strSql.ToString());
}
/// <summary>
/// 获得数据列表
/// </summary>
public DataSet GetList( string strWhere,StringBuilder sbfield,StringBuilder sbon)
{
StringBuilder strSql
= new StringBuilder();
strSql.Append(
@" select T.id,
T.name
" );
if (sbfield.ToString () != string .Empty )
{
strSql.Append(
" , " + sbfield.ToString()) ;
}
strSql.Append(
" FROM temp AS T WITH (NOLOCK) " );
if (sbon.ToString () != string .Empty )
{
sbon.ToString ();
}
if (strWhere.Trim() != "" )
{
strSql.Append(
" where " + strWhere);
}
return DbHelperSQL.Query(strSql.ToString());
}
/// <summary>
/// 获得数据列表
/// </summary>
public DataSet GetList(StringBuilder strSql)
{
return DbHelperSQL.Query(strSql.ToString());
}

/// <summary>
/// 获得前几行数据
/// </summary>
public DataSet GetList( int Top, string strWhere, string filedOrder)
{
StringBuilder strSql
= new StringBuilder();
strSql.Append(
" select " );
if (Top > 0 )
{
strSql.Append(
" top " + Top.ToString());
}
strSql.Append(
" id,name " );
strSql.Append(
" FROM temp with(nolock) " );
if (strWhere.Trim() != "" )
{
strSql.Append(
" where " + strWhere);
}
if (filedOrder != string .Empty)
{
strSql.Append(
" order by " + filedOrder);
}
return DbHelperSQL.Query(strSql.ToString());
}

/// <summary>
/// 获得数据列表
/// </summary>
public int fnQuery( string strWhere,DataTable table, bool AutoClear)
{
StringBuilder strSql
= new StringBuilder();
strSql.Append(
" select id,name " );
strSql.Append(
" FROM temp with(nolock) " );
if (strWhere.Trim() != "" )
{
strSql.Append(
" where " + strWhere);
}
return fnGetList(strSql.ToString(), table, AutoClear);
}
/// <summary>
/// 获得数据列表
/// </summary>
public int fnQuery( string strWhere, string strselect,DataTable table, bool AutoClear)
{
StringBuilder strSql
= new StringBuilder();
strSql.Append(
" select " + strselect);
strSql.Append(
" FROM temp with(nolock) " );
if (strWhere.Trim() != "" )
{
strSql.Append(
" where " + strWhere);
}
return fnGetList(strSql.ToString(), table, AutoClear);
}
/// <summary>
/// 获得数据列表
/// </summary>
public int fnQuery( string strWhere,StringBuilder sbfield,StringBuilder sbon,DataTable table, bool AutoClear)
{
StringBuilder strSql
= new StringBuilder();
strSql.Append(
@" select T.id,
T.name
" );
if (sbfield.ToString () != string .Empty )
{
strSql.Append(
" , " + sbfield.ToString()) ;
}
strSql.Append(
" FROM temp AS T WITH (NOLOCK) " );
if (sbon.ToString () != string .Empty )
{
sbon.ToString ();
}
if (strWhere.Trim() != "" )
{
strSql.Append(
" where " + strWhere);
}
return fnGetList(strSql.ToString(), table, AutoClear);
}
/// <summary>
/// 获得数据列表
/// </summary>
public int fnQuery(StringBuilder strSql,DataTable table, bool AutoClear)
{
return fnGetList(strSql.ToString(), table, AutoClear);
}

/// <summary>
/// 获得前几行数据
/// </summary>
public int fnQuery( int Top, string strWhere, string filedOrder,DataTable table, bool AutoClear)
{
StringBuilder strSql
= new StringBuilder();
strSql.Append(
" select " );
if (Top > 0 )
{
strSql.Append(
" top " + Top.ToString());
}
strSql.Append(
" id,name " );
strSql.Append(
" FROM temp with(nolock) " );
if (strWhere.Trim() != "" )
{
strSql.Append(
" where " + strWhere);
}
if (filedOrder != string .Empty)
{
strSql.Append(
" order by " + filedOrder);
}
return fnGetList(strSql.ToString(), table, AutoClear);
}

/// <summary>
/// 通用查询语句
/// </summary>
public int fnGetList( string sqlstr,DataTable table, bool AutoClear)
{
DataSet ds
= DbHelperSQL.Query(sqlstr);
if (ds == null )
{
return - 1 ;
}
if (ds.Tables.Count < 1 )
{
return - 1 ;
}
if (AutoClear)
{
table.Clear();
}
table.Merge(ds.Tables[
0 ]);
return ds.Tables[ 0 ].Rows.Count;
}

/*
/// <summary>
/// 分页获取数据列表
/// </summary>
public DataSet GetList(int PageSize,int PageIndex,string strWhere)
{
SqlParameter[] parameters = {
new SqlParameter("@tblName", SqlDbType.VarChar, 255),
new SqlParameter("@fldName", SqlDbType.VarChar, 255),
new SqlParameter("@PageSize", SqlDbType.Int),
new SqlParameter("@PageIndex", SqlDbType.Int),
new SqlParameter("@IsReCount", SqlDbType.Bit),
new SqlParameter("@OrderType", SqlDbType.Bit),
new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
};
parameters[0].Value = "temp";
parameters[1].Value = "ID";
parameters[2].Value = PageSize;
parameters[3].Value = PageIndex;
parameters[4].Value = 0;
parameters[5].Value = 0;
parameters[6].Value = strWhere;
return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
}
*/

#endregion 成员方法
}
}
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:26146次
    • 积分:466
    • 等级:
    • 排名:千里之外
    • 原创:19篇
    • 转载:12篇
    • 译文:0篇
    • 评论:2条