某君的部分SqlHelper

原创 2011年01月19日 09:46:00
///
 
<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 成员方法
}
}

相关文章推荐

SQLHelper类

  • 2017年10月30日 14:17
  • 52KB
  • 下载

微软SqlHelper.cs数据访问帮助类

说明文件 http://www.microsoft.com/china/MSDN/library/EnterpriseDevelopment/BuildDistApp/Vsdnbdadaab_rm.m...

sqlhelper sqlserver

  • 2014年08月16日 09:25
  • 3KB
  • 下载

牛腩新闻发布系统(二):SQLHelper重构(二)

导读:在上一篇博客中,介绍了简单的SQLHelper重构,即数据库链接,打开和关闭链接的优化等。现在,将介绍参数化查询和执行命令类型的改造。 一、必要性 1,参数化查询 在上篇博客中,在查询的时候,仅...

SqlHelper For Sqlserver经典设计

  • 2014年06月24日 12:41
  • 12KB
  • 下载

Microsoft SQLHelper 2.0 (C#)

  • 2012年05月11日 07:56
  • 10KB
  • 下载

机房重构(1)——SqlHelper

在机房重构过程中,我们会发现,
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:某君的部分SqlHelper
举报原因:
原因补充:

(最多只允许输入30个字)