Beispiel #1
0
 /// <summary>
 /// Executes the SQL statement using <see cref="OleDbConnection"/>, and returns the value in the first column 
 /// of the first row in the resultset.
 /// </summary>
 /// <param name="sql">The SQL statement to be executed.</param>
 /// <param name="connection">The <see cref="OleDbConnection"/> to use for executing the SQL statement.</param>
 /// <param name="timeout">The time in seconds to wait for the SQL statement to execute.</param>
 /// <param name="parameters">The parameters to be passed to the SQL stored procedure being executed.</param>
 /// <returns>Value in the first column of the first row in the resultset.</returns>
 public static object ExecuteScalar(this OleDbConnection connection, string sql, int timeout, params object[] parameters)
 {
     OleDbCommand command = new OleDbCommand(sql, connection);
     command.CommandTimeout = timeout;
     command.PopulateParameters(parameters);
     return command.ExecuteScalar();
 }
Beispiel #2
0
        /// <summary>
        /// Executes the SQL statement using <see cref="OleDbConnection"/>, and returns the <see cref="DataSet"/> that 
        /// may contain multiple tables, depending on the SQL statement.
        /// </summary>
        /// <param name="sql">The SQL statement to be executed.</param>
        /// <param name="connection">The <see cref="OleDbConnection"/> to use for executing the SQL statement.</param>
        /// <param name="startRow">The zero-based record number to start with.</param>
        /// <param name="maxRows">The maximum number of records to retrieve.</param>
        /// <param name="timeout">The time in seconds to wait for the SQL statement to execute.</param>
        /// <param name="parameters">The parameters to be passed to the SQL stored procedure being executed.</param>
        /// <returns>A <see cref="DataSet"/> object.</returns>
        public static DataSet RetrieveDataSet(this OleDbConnection connection, string sql, int startRow, int maxRows, int timeout, params object[] parameters)
        {
            OleDbCommand command = new OleDbCommand(sql, connection);

            command.PopulateParameters(parameters);
            OleDbDataAdapter dataAdapter = new OleDbDataAdapter(command);
            DataSet data = new DataSet("Temp");
            dataAdapter.Fill(data, startRow, maxRows, "Table1");

            return data;
        }
Beispiel #3
0
 /// <summary>
 /// Executes the SQL statement using <see cref="OleDbConnection"/>, and builds a <see cref="OleDbDataReader"/>.
 /// </summary>
 /// <param name="sql">The SQL statement to be executed.</param>
 /// <param name="connection">The <see cref="OleDbConnection"/> to use for executing the SQL statement.</param>
 /// <param name="behavior">One of the <see cref="CommandBehavior"/> values.</param>
 /// <param name="timeout">The time in seconds to wait for the SQL statement to execute.</param>
 /// <param name="parameters">The parameters to be passed to the SQL stored procedure being executed.</param>
 /// <returns>A <see cref="OleDbDataReader"/> object.</returns>
 public static OleDbDataReader ExecuteReader(this OleDbConnection connection, string sql, CommandBehavior behavior, int timeout, params object[] parameters)
 {
     OleDbCommand command = new OleDbCommand(sql, connection);
     command.CommandTimeout = timeout;
     command.PopulateParameters(parameters);
     return command.ExecuteReader(behavior);
 }