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