The OleDbCommand and SqlCommand classes represent the objectification of stored procedures and SQL. You need a way to send SQL text, stored procedures, and their incumbent parameters to data providers, and in .NET, you use the command object for this purpose. Listing 11.7 provides an example showing how to use a command object. Chapter 12 includes an example using a stored procedure.
Listing 11.7 Filling a DataSet by Using SQL and an OleDbCommand Object
Private Sub InitializeGridWithCommand() Dim Connection As OleDbConnection = _ New OleDbConnection(Database.ConnectionString) Dim Command As OleDbCommand = _ New OleDbCommand("SELECT * FROM CUSTOMERS", Connection) Dim Adapter As OleDbDataAdapter = _ New OleDbDataAdapter(Command) Dim Customers As DataTable = New DataTable("Customers") Adapter.Fill(Customers) DataGrid1.DataSource = Customers DataGrid1.DataBind() End Sub
Notice that Listing 11.7 is almost identical to Listing 11.5. The obvious difference is that I substituted literal SQL text to initialize the adapter with a command object.