/// <summary>
/// Execute SQL(insert,delete,update)command,return the number of the rows which are affected
/// </summary>
/// <param>SQL Command which will be Executed</param>
/// <returns>return the number of the rows which are affected</returns>
public int ExecuteSql(string strSql)
{
debug("Now Execute DataBaseAccess's Method:ExecuteSql(string),Return Type:int ");
return ExecuteSql(new SqlCommand(strSql,this.conn));
}
/// <summary>
/// Execute SQL(insert,delete,update)command,return the number of the rows which are affected.
/// </summary>
/// <param>SQL Command which will be Executed</param>
/// <param>SQL Parameter</param>
/// <returns>return the number of the rows which are affected</returns>
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
/// <summary>
/// Execute mutil-SQL(insert,delete,update)command,keep an affair.
/// </summary>
/// <param>SQL Command collection which will be Executed</param>
/// <param>if true,once one SQL Execute,the result of the execution is invalid,if false,ignore the result and rollback.</param>
/// <returns>return the list number of the rows which are affected</returns>
public List<int> ExecuteSqlDic(Dictionary<string, SqlParameter[]> dic, bool bNotAffectRowRollback)
{
debug("Now Execute DataBaseAccess's Method:ExecuteSqlDic(Dictionary<string, SqlParameter[]>, bool),Return Type:List<int> ");
List<int> iReturnValueList = new List<int>();
this.conn.Open();
SqlTransaction trans = this.conn.BeginTransaction();
try
{
foreach (KeyValuePair<string, SqlParameter[]> 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.Clear();
return iReturnValueList;
}
}
trans.Commit();
}
catch (SqlException ex)
{
debug("Exception Information:" + ex.ToString());
trans.Rollback();
throw ex;
}
finally
{
this.conn.Close();
}
return iReturnValueList;
}