Beispiel #1
0
        /// <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));
        }
Beispiel #2
0
        /// <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));
        }
Beispiel #3
0
        /// <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);
        }
Beispiel #4
0
        /// <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();
        }