Exemple #1
0
 /// <summary>
 /// Executes the SQL statement using <see cref="IDbCommand"/>, 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="command">The <see cref="IDbCommand"/> 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 parameter values to be used to fill in <see cref="IDbDataParameter"/> parameters identified by '@' prefix in <paramref name="sql"/> expression.</param>
 /// <returns>Value in the first column of the first row in the resultset.</returns>
 public static object ExecuteScalar(this IDbCommand command, string sql, int timeout, params object[] parameters)
 {
     command.CommandTimeout = timeout;
     command.Parameters.Clear();
     command.AddParametersWithValues(sql, parameters);
     return command.ExecuteScalar();
 }
Exemple #2
0
        /// <summary>
        /// Executes the SQL statement using <see cref="IDbCommand"/>, and returns the <see cref="DataSet"/> that 
        /// may contain multiple tables, depending on the SQL statement.
        /// </summary>
        /// <param name="command">The <see cref="IDbCommand"/> to use for executing the SQL statement.</param>
        /// <param name="dataAdapterType">The <see cref="Type"/> of data adapter to use to retreieve data.</param>
        /// <param name="sql">The SQL statement to be executed.</param>
        /// <param name="timeout">The time in seconds to wait for the SQL statement to execute.</param>
        /// <param name="parameters">The parameter values to be used to fill in <see cref="IDbDataParameter"/> parameters identified by '@' prefix in <paramref name="sql"/> expression.</param>
        /// <returns>A <see cref="DataSet"/> object.</returns>
        public static DataSet RetrieveDataSet(this IDbCommand command, Type dataAdapterType, string sql, int timeout, params object[] parameters)
        {
            command.CommandTimeout = timeout;
            command.Parameters.Clear();
            command.AddParametersWithValues(sql, parameters);
            IDataAdapter dataAdapter = (IDataAdapter)Activator.CreateInstance(dataAdapterType, command);
            DataSet data = new DataSet("Temp");
            dataAdapter.Fill(data);

            return data;
        }
Exemple #3
0
 /// <summary>
 /// Executes the SQL statement using <see cref="IDbCommand"/>, and builds a <see cref="IDataReader"/>.
 /// </summary>
 /// <param name="sql">The SQL statement to be executed.</param>
 /// <param name="command">The <see cref="IDbCommand"/> 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 parameter values to be used to fill in <see cref="IDbDataParameter"/> parameters identified by '@' prefix in <paramref name="sql"/> expression.</param>
 /// <returns>A <see cref="IDataReader"/> object.</returns>
 public static IDataReader ExecuteReader(this IDbCommand command, string sql, CommandBehavior behavior, int timeout, params object[] parameters)
 {
     command.CommandTimeout = timeout;
     command.Parameters.Clear();
     command.AddParametersWithValues(sql, parameters);
     return command.ExecuteReader(behavior);
 }