设为首页 加入收藏

TOP

[C#]分享一个以前的项目使用的DataBaseAccess类(二)
2014-11-24 14:34:34 来源: 作者: 【 】 浏览:4
Tags:分享 一个 以前 项目 使用 DataBaseAccess
turn the number of the rows which are affected
public int ExecuteSql(SqlCommand sqlcmd)
{
debug("Now Execute DataBaseAccess's Method:ExecuteSql(SqlCommand),Return Type:int ");
this.conn.Open();
sqlcmd.Connection = this.conn;
SqlTransaction trans = this.conn.BeginTransaction();
sqlcmd.Transaction = trans;
try
{
debug("Execute SQL Command:" + sqlcmd.CommandText);
int iReturnValue = sqlcmd.ExecuteNonQuery();
trans.Commit();
return iReturnValue;
}
catch (SqlException ex)
{
debug("Exception Information:" + ex.ToString());
trans.Rollback();
throw ex;
}
finally
{
sqlcmd.Dispose();
this.conn.Close();
}
}


///


/// Execute SQL(insert,delete,update)command,return the number of the rows which are affected
///

/// SQL Command which will be Executed
/// return the number of the rows which are affected
public int ExecuteSql(string strSql)
{
debug("Now Execute DataBaseAccess's Method:ExecuteSql(string),Return Type:int ");
return ExecuteSql(new SqlCommand(strSql,this.conn));
}


///


/// Execute SQL(insert,delete,update)command,return the number of the rows which are affected.
///

/// SQL Command which will be Executed
/// SQL Parameter
/// return the number of the rows which are affected
public int ExecuteSql(string strSql, SqlParameter[] sqlParameters)
{
debug("Now Execute DataBaseAccess's Method:ExecuteSql(string, SqlParameter[]),Return Type:int ");
return ExecuteSql(SQLHelper.CreateCommand(strSql, sqlParameters, this.conn));
}


#endregion


#region ExecuteSqlDic


///


/// Execute mutil-SQL(insert,delete,update)command,keep an affair.
///

/// SQL Command collection which will be Executed
/// if true,once one SQL Execute,the result of the execution is invalid,if false,ignore the result and rollback.
/// return the list number of the rows which are affected
public List ExecuteSqlDic(Dictionary dic, bool bNotAffectRowRollback)
{
debug("Now Execute DataBaseAccess's Method:ExecuteSqlDic(Dictionary, bool),Return Type:List ");
List iReturnValueList = new List();
this.conn.Open();
SqlTransaction trans = this.conn.BeginTransaction();
try
{
foreach (KeyValuePair kvp in dic)
{
SqlCommand sqlcmd = SQLHelper.CreateCommand(kvp.Key, kvp.Value, this.conn);
sqlcmd.Transaction = trans;
debug("Execute SQL Command:" + sqlcmd.CommandText);
int iAffectRow=sqlcmd.ExecuteNonQuery();
iReturnValueList.Add(iAffectRow);
if (bNotAffectRowRollback && iAffectRow == 0)
{
trans.Rollback();
iReturnValueList.Cle
首页 上一页 1 2 3 4 5 6 7 下一页 尾页 2/10/10
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇C# 在winform画面上点击某个区域.. 下一篇C#中生成验证码的类

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: