A simple-bound control reads one row or field at a time while a complex- bound control is one that looks at the entire recordset. For example, a textbox is a simple-bound control but a grid is a complex-bound control. The data bound listbox and combobox controls are complex-bound because they read the entire recordset to provide the list of available data.
Complex-bound controls require that the recordset be bound to support navigation and bookmarks. This functionality is required for the control to read the data in the recordset and know that it can later find that particular row. You may receive an error if you try to bind a complex-bound control to a data source whose data does not support this functionality.
- Create a new Standard EXE project. Form1 is created by default.
- Under Project, References, select the Microsoft ActiveX Data Objects Library.
- On the Project menu, click Components. On the Controls tab, select the check box next to the Microsoft DataGrid Control 6.0 (OLEDB) option. Then click OK to exit the Components window.
- Add a DataGrid to the form.
- Add the following code to the form. Be sure to change the value of the strConn variable so that it points to the location of the Northwind (NWind.MDB) database on your machine:
Dim cnNWind As New ADODB.Connection
Dim rsOrders As New ADODB.Recordset
Private Sub Form_Load()
Dim strConn As String
strConn = "Provider=Microsoft.Jet.OLEDB.3.51;" & _
'If using an Access 2000 mdb use "Microsoft.Jet.OLEDB.4.0"
cnNWind.CursorLocation = adUseClient
rsOrders.Open "SELECT OrderID, EmployeeID, OrderDate FROM Orders", _
cnNWind, adOpenStatic, adLockOptimistic, adCmdText
Set DataGrid1.DataSource = rsOrders
- Run the code and you will see data in the grid on your form.
- Modify the code by changing the adOpenStatic constant to adOpenForwardOnly and the CursorLocation to adUseServer.
- Run the code and you should see an error message that says "The rowset is not bookmarkable."
Id. de artículo: 189668 - Última revisión: 08/04/2008 - Revisión: 1