Datasheet
3. Save the page and run it as shown in Figure 8-5:
Figure 8-5
Amazing! A sortable grid full of data and you didn't have to write even a single line of code!
How It Works
The workings rely on two controls – the AccessDataSourceControl that provides the connection to
the database, and an
MxDataGrid, which is a Web Matrix control (also covered in Chapter 10) that
displays the data. Looking at the HTML view for these controls gives you a good idea of what they do.
Let's start with the
AccessDataSourceControl:
<wmx:AccessDataSourceControl id="AccessDataSourceControl2"
runat="server" SelectCommand="SELECT * FROM [Suppliers]"
ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0; Ole DB Services=-4;
Data Source=C:\BegASPNET11\data\Northwind.mdb"></wmx:AccessDataSourceControl>
The first thing to notice is the way the control is declared. You're used to seeing asp: at the beginning of
controls, but not
wmx:. This prefix is the namespace – remember the previous chapter where we said that
namespaces provide a separation between classes. In this case, these controls are part of Web Matrix, and
have thus been given a namespace that is different from the standard server controls.
Apart from the
id and runat, two other attributes provide the details regarding which database to
connect to and what data to fetch:
❑ The
SelectCommand: Defines the SQL that will return the required data – in this case, it's all
rows and columns from the
Suppliers table. This is the default since we dragged this table,
but we can customize the
SelectCommand to return only selected rows or columns.
❑ The
ConnectionString: Defines the OLEDB connection string. You only need to worry about
the bit with the path of the database file – the
Data Source bit (if you move the file, you'll need
to change this). The other parts of the ConnectionString just define the type of database and
254
Chapter 8
57084_08.qxp 30/01/2004 8:03 PM Page 254