Free mag vol1 | Page 864

CHAPTER 21  ADO.NET PART I: THE CONNECTED LAYER public interface IDbCommand : IDisposable { string CommandText { get; set; } int CommandTimeout { get; set; } CommandType CommandType { get; set; } IDbConnection Connection { get; set; } IDataParameterCollection Parameters { get; } IDbTransaction Transaction { get; set; } UpdateRowSource UpdatedRowSource { get; set; } } void Cancel(); IDbDataParameter CreateParameter(); int ExecuteNonQuery(); IDataReader ExecuteReader(); IDataReader ExecuteReader(CommandBehavior behavior); object ExecuteScalar(); void Prepare(); The Role of the IDbDataParameter and IDataParameter Interfaces Notice that the Parameters property of IDbCommand returns a strongly typed collection that implements IDataParameterCollection. This interface provides access to a set of IDbDataParameter-compliant class types (e.g., parameter objects). public interface IDbDataParameter : IDataParameter { byte Precision { get; set; } byte Scale { get; set; } int Size { get; set; } } IDbDataParameter extends the IDataParameter interface to obtain the following additional behaviors: public interface IDataParameter { DbType DbType { get; set; } ParameterDirection Direction { get; set; } bool IsNullable { get; } string ParameterName { get; set; } string SourceColumn { get; set; } DataRowVersion SourceVersion { get; set; } object Value { get; set; } } As you will see, the functionality of the IDbDataParameter and IDataParameter interfaces allows you to represent parameters within a SQL command (including stored procedures) through specific ADO.NET parameter objects, rather than through hard-coded string literals. 810