public static IDataReader GetDataReader( string query, CommandType commandType, Dictionary<string, object> parameters )
{
string connectionString = GetConnectionString();
if ( !string.IsNullOrWhiteSpace( connectionString ) )
{
SqlConnection con = new SqlConnection( connectionString );
con.Open();
SqlCommand sqlCommand = new SqlCommand( query, con );
sqlCommand.CommandType = commandType;
if ( parameters != null )
{
foreach ( var parameter in parameters )
{
SqlParameter sqlParam = new SqlParameter();
sqlParam.ParameterName = parameter.Key.StartsWith( "@" ) ? parameter.Key : "@" + parameter.Key;
sqlParam.Value = parameter.Value;
sqlCommand.Parameters.Add( sqlParam );
}
}
return sqlCommand.ExecuteReader( CommandBehavior.CloseConnection );
}
return null;
}