System.Data.SqlClient Namespace SqlParameterCollection Class
Adds an SqlParameter to the parameters collection.
1. Adds a new SqlParameter object to the parameters collection.
2. Adds a specified SqlParameter object to the parameters collection.
3. Adds an SqlParameter with the specified name and value to the parameters collection.
4. Adds an SqlParameter with the specified name and data type to the parameters collection.
5. Adds an SqlParameter with the specified name, data type, and column width to the parameters collection.
6. Adds an SqlParameter with the specified name, data type, column width, and source column name to the parameters collection.
The following example adds a new SqlParameter.
NOTE: This example shows how to use one of the overloaded versions of Add. For other examples that may be available, see the individual overload topics.
public void CreateSqlParamColl ( SqlConnection myConn ) {
SqlCommand myCmd = new SqlCommand (
"SELECT * FROM Customers WHERE CustomerID = @CustomerID", myConn );
SqlParameterCollection myParams = myCmd.Parameters;
SqlParameter myParam = myParams.Add ( new SqlParameter (
"@CustomerID", SqlDbType.VarChar, 5, "CustomerID" ) );
}
Public Sub CreateSqlParamColl ( myConn As SqlConnection )
Dim myCmd As New SqlCommand ( _
"SELECT * FROM Customers WHERE CustomerID = @CustomerID", myConn )
Dim myParams As SqlParameterCollection = myCmd.Parameters
Dim myParam As SqlParameter = myParams.Add ( New SqlParameter ( _
"@CustomerID", SqlDbType.VarChar, 5, "CustomerID" ) )
End Sub |
|
C# |
VB |
SqlParameterCollection Members
|
|