/// <summary>
/// Execute SQL Command,return SqlDataReader.
/// </summary>
/// <param>SQL Command which will be Executed</param>
/// <returns>Return SqlDataReader</returns>
public SqlDataReader ExecuteSqlDr(SqlCommand sqlcmd)
{
debug("Now Execute DataBaseAccess's Method:ExecuteSqlDr(SqlCommand),Return Type:SqlDataReader ");
sqlcmd.Connection = this.conn;
SqlDataReader sqldr;
try
{
debug("Execute SQL Command:" + sqlcmd.CommandText.ToString());
this.conn.Open();
sqldr = sqlcmd.ExecuteReader(CommandBehavior.CloseConnection);
return sqldr;
}
catch (SqlException ex)
{
debug("Exception information:" + ex.ToString());
throw ex;
}
finally
{
sqlcmd.Dispose();
}
}
/// <summary>
/// Execute SQL Command,return SqlDataReader.
/// </summary>
/// <param>SQL Command which will be Executed</param>
/// <returns>Return SqlDataReader</returns>
public SqlDataReader ExecuteSqlDr(string strSql)
{
debug("Now Execute DataBaseAccess's Method:ExecuteSqlDr(string),Return Type:SqlDataReader ");
return ExecuteSqlDr(new SqlCommand(strSql));
}
/// <summary>
/// Execute SQL Command,return SqlDataReader.
/// </summary>
/// <param>SQL Command which will be Executed</param>
/// <param>SQL Parameters Collection</param>
/// <returns>Return SqlDataReader</returns>
public SqlDataReader ExecuteSqlDr(string strSql, SqlParameter[] sqlParameters)
{
debug("Now Execute DataBaseAccess's Method:ExecuteSqlDr(string, SqlParameter[]),Return Type:SqlDataReader ");
return ExecuteSqlDr(SQLHelper.CreateCommand(strSql, sqlParameters, this.conn));
}
#endregion
#region ExecuteSqlTarn
/// <summary>
/// Execute SQL Command,Keep affair.
/// </summary>
/// <param>SQL Command which will be Executed</param>
/// <param>SQL Parameters Collection</param>
public void ExecuteSqlTran(string strSql, SqlParameter[] sqlParameters)
{
conn.Open();
SqlCommand sqlcmd = SQLHelper.CreateCommand(strSql, sqlParameters, this.conn);
using(SqlTransaction sqltrans = this.conn.BeginTransaction())
{
sqlcmd.Transaction = sqltrans;
try
{
sqlcmd.ExecuteNonQuery();
sqltrans.Commit();
}
catch (System.Data.SqlClient.SqlException E)
{
sqltrans.Rollback();
throw E;
}
finally
{
sqlcmd.Dispose();
this.conn.Close();
}
}
}