IDbCommand.Parameters Property

 
Namespace:   System.Data
Assembly:  System.Data (in System.Data.dll)

ReadOnly Property Parameters As IDataParameterCollection

Property Value

Type: System.Data.IDataParameterCollection

The parameters of the SQL statement or stored procedure.

The following example creates an instance of the derived class, SqlCommand, and displays its parameters. In the example, the application passes a SqlConnection, a query string that is a Transact-SQL SELECT statement, and an array of SqlParameter objects.

Public Sub CreateSqlCommand(ByVal connection As SqlConnection, _
ByVal queryString As String, ByVal params() As SqlParameter)

    Dim command As New SqlCommand(queryString, connection)
    command.CommandText = _
       "SELECT CustomerID, CompanyName FROM Customers " _
       & "WHERE Country = @Country AND City = @City"
    command.UpdatedRowSource = UpdateRowSource.Both
    command.Parameters.Add(params)

    Dim j As Integer
    For j = 0 To command.Parameters.Count - 1
        command.Parameters.Add(params(j))
    Next j

    Dim message As String = ""
    Dim i As Integer
    For i = 0 To command.Parameters.Count - 1
        message += command.Parameters(i).ToString() & ControlChars.Cr
    Next i

    Console.WriteLine(message)
End Sub

.NET Framework
Available since 1.1
Return to top
Show: