Properties of the SqlParameter Class
| Properties |
| DbType |
Contains the data type of the SQL parameter |
| Direction |
Defines whether the parameter is input or output |
| IsNullable |
Defines whether the parameter can be null |
| ParameterName |
Contains the name of the parameter |
| Precision |
Contains the precision of the parameter |
| Scale |
Contains the scale of the parameter |
| Size |
Contains the size of the parameter |
| Value |
Contains the value of the parameter |
SqlParameter.DbType
Syntax
SqlDbType DbType
Description
The DbType property is set to the SQL data type that is expected by the stored procedure. Any of the values in the System.Data.SqlClient.SqlDbType namespace are acceptable.
Example
SqlParameter param = new SqlParameter();
param.DbType = SqlDbType.NVarChar;
SqlParameter.Direction
Syntax
ParameterDirection Direction
Description
The Direction property sets the direction of the parameter and should match the stored procedure. Acceptable values for this property are found in the System.Data.SqlClient.ParameterDirection namespace.
Example
SqlParameter param = new SqlParameter();
param.Direction = ParameterDirection.Input;
SqlParameter.IsNullable
Syntax
Boolean IsNullable
Description
The IsNullable property specifies whether the parameter is allowed to be null.
Example
SqlParameter param = new SqlParameter();
param.IsNullable = true;
SqlParameter.ParameterName
Syntax
String ParameterName
Description
The ParameterName property specifies the name of the parameter that the stored procedure is expecting.
Example
param.ParameterName = "@ProductID";
SqlParameter.Precision
Syntax
Byte Precision
Description
The Precision property is used to specify the number of digits used to represent the value of the parameter.
Example
SqlParameter param = new SqlParameter();
param.Precision = 2;
SqlParameter.Scale
Syntax
Byte Scale
Description
The Scale property is used to specify the number of decimal places in the value of the parameter.
Example
SqlParameter param = new SqlParameter();
param.Scale = 2;
SqlParameter.Size
Syntax
Int32 Size
Description
The Size property specifies the size of the parameter that the stored procedure is expecting.
Example
SqlParameter param = new SqlParameter();
param.Size = 7;
SqlParameter.Value
Syntax
Object Value
Description
The Value property is used to specify the value of the parameter that will be passed to the stored procedure.
Example
SqlParameter param = new SqlParameter();
param.Value = "Test";
|