/// <summary> /// Executes the sql statement and saves the results in a DataSet /// If multiple querries are defined, DataSet will contain more than one table /// </summary> /// <param name="sql">SQL String ex: select * from Products</param> /// <param name="library">The related data library</param> /// <returns>DataSet Containing the querry execution results</returns> public static DataSet GetDataSet(string sql, string library) { DirectorBase db = new DirectorBase(library); SqlConnection connection = (SqlConnection)db.GetConnection(); return(GetDataSet(sql, connection)); }
/// <summary> /// SqlDataReader (remember to close the reader when finished) /// </summary> /// <param name="sql">SQL String</param> /// <param name="library">DataLibrary</param> /// <returns>SqlDataReader instance</returns> public static SqlDataReader ExecuteReader(string sql, string library) { DirectorBase db = new DirectorBase(library); SqlConnection connection = (SqlConnection)db.GetConnection(); SqlCommand cmd = new SqlCommand(); cmd.CommandText = sql; cmd.Connection = connection; cmd.Connection.Open(); return(cmd.ExecuteReader(CommandBehavior.CloseConnection)); }
/// <summary> /// Creates a stored procedure command /// this methos only created the Command /// in order to execute you must call the Command.Execute or any relevant function /// </summary> /// <param name="name">Stored Procedure name</param> /// <param name="library">DataLibrary</param> /// <returns>The procedure as command, parameters can be added using the AddProcedureParameter method</returns> public static SqlCommand StoredProcedure(string name, string library) { DirectorBase db = new DirectorBase(library); SqlConnection connection = (SqlConnection)db.GetConnection(); SqlCommand command = new SqlCommand(); command.CommandText = name; command.CommandType = CommandType.StoredProcedure; command.Connection = connection; return(command); }
/// <summary> /// Executes an sql query /// </summary> /// <param name="sql">SQL String</param> /// <param name="library">Data Library</param> public static void ExecuteQuery(string sql, string library) { DirectorBase db = new DirectorBase(library); SqlConnection connection = (SqlConnection)db.GetConnection(); SqlCommand cmd = new SqlCommand(); cmd.CommandText = sql; cmd.Connection = connection; cmd.Connection.Open(); cmd.ExecuteNonQuery(); cmd.Connection.Close(); }