Public Sub ReadOrderData(ByVal connectionString As String)
Dim queryString As String = _
"SELECT OrderID, CustomerID FROM dbo.Orders;"
Using connection As New SqlConnection(connectionString)
Dim command As New SqlCommand(queryString, connection)
connection.Open()
Dim reader As SqlDataReader = command.ExecuteReader()
Try
While reader.Read()
Console.WriteLine(String.Format("{0}, {1}", _
reader(0), reader(1)))
End While
Finally
' Always call Close when done reading.
reader.Close()
End Try
End Using
End Sub

Remarks

The IDbCommand interface enables an inheriting class to implement a Command class, which represents an SQL statement that is executed at a data source. For more information about Command classes, see Executing a Command.

An application does not create an instance of the IDbCommand interface directly, but creates an instance of a class that implements the IDbCommand interface.

Classes that implement IDbCommand must implement all its members, and typically define additional members to add provider-specific functionality. For example, the IDbCommand interface defines the ExecuteNonQuery method. In turn, the SqlCommand class inherits this method, and also defines the ExecuteXmlReader method.

Notes to Implementers

To promote consistency among .NET Framework data providers, name the inheriting class in the form PrvClassname where Prv is the uniform prefix given to all classes in a specific .NET Framework data provider namespace. For example, Sql is the prefix of the SqlCommand class in the System.Data.SqlClient namespace.

When you inherit from the IDbCommand interface, you should implement the following constructors:

Item

Description

PrvCommand()

Initializes a new instance of the PrvCommand class.

PrvCommand(string cmdText)

Initializes a new instance of the PrvCommand class with the text of the query.

PrvCommand(string cmdText, PrvConnection connection)

Initializes a new instance of the PrvCommand class with the text of the query and a PrvConnection.