Add(String,SqlType,Int32,String) Method
Adds a
SqlParameter to the
SqlParameterCollection given the parameter name, data type, column width, and source column name.
The following example creates a
SqlParameterCollection, adds instances of
SqlParameter to the collection, and returns a reference to the new
SqlParameter.
|
|---|
public void CreateSqlParamColl(SqlConnection myConn) {
SqlCommand myCommand = new SqlCommand("SELECT * FROM Test.Dept WHERE DeptNo = :DeptNo", myConn);
SqlParameterCollection myParamCollection = myCommand.Parameters;
SqlParameter myNewParameter = myParamCollection.Add("DeptNo", SqlType.Int, 40, "DeptNo");
} |
|
|---|
Public Sub CreateSqlParamColl(myConn As SqlConnection)
Dim myCommand As SqlCommand = New SqlCommand("SELECT * FROM Test.Dept WHERE DeptNo = :DeptNo", myConn)
Dim myParamCollection As SqlParameterCollection = myCommand.Parameters
Dim myNewParameter As SqlParameter = myParamCollection.Add("DeptNo", SqlType.Int, 40, "DeptNo")
End Sub |