Represents an SQL statement or stored procedure to execute against a data source.
Assembly: System.Data (in System.Data.dll)
When an instance of is created, the read/write properties are set to their initial values. For a list of these values, see the constructor.
features the following methods executing commands at a data source:
Executes commands that return rows. ExecuteReader may not have the effect that you want if used to execute commands such as SQL SET statements.
Executes commands such as SQL INSERT, DELETE, UPDATE, and SET statements.
Retrieves a single value, for example, an aggregate value from a database.
If a fatal OleDbException (for example, a SQL Server severity level of 20 or greater) is generated by the method executing an , the OleDbConnection, the connection may be closed. However, the user can reopen the connection and continue.
The following example uses the , along OleDbDataAdapter and OleDbConnection, to select rows from an Access database. The filled DataSet is then returned. The example is passed an initialized DataSet, a connection string, a query string that is an SQL SELECT statement, and a string that is the name of the source database table.
Public Sub ReadMyData(ByVal connectionString As String) Dim queryString As String = "SELECT OrderID, CustomerID FROM Orders" Using connection As New OleDbConnection(connectionString) Dim command As New OleDbCommand(queryString, connection) connection.Open() Dim reader As OleDbDataReader = command.ExecuteReader() While reader.Read() Console.WriteLine(reader.GetInt32(0).ToString() + ", " _ + reader.GetString(1)) End While ' always call Close when done reading. reader.Close() End Using End Sub
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.