first_page the funky knowledge base
personal notes from way, _way_ back and maybe today

MCAD/MCSD Notes: Chapter 5, Lesson 1; Accessing Data with ADO.NET

Lesson 1: Accessing Data with ADO.NET

The purpose of this lesson is to provide an overview of ADO.NET and suggest design patterns featuring ADO.NET in ASP.NET. The center of the ADO.NET 1.x universe is the DataSet and the strongly typed dataset, extending the DataSet class, which is generated automatically in Visual Studio .NET.

There are four data access layers in ADO.NET (in order of execution): the physical data store, the data provider (the connection and adapter), the data set and the data view. ADO.NET 1.x shipped with three data providers: OLEDB, SQL and Oracle.

Unfortunately this feature is not explored in this lesson but will resurface in Chapter 7.

These "three" namespaces are: System.Data, System.Data.SqlClient, System.Data.OracleClient and System.Data.OleDb. These three namespaces lead to the three steps of database access: define a connection to the physical data store, define a set of commands to adapt the physical data store into a DataSet object, execute the commands.

Namely, this applies to the data adapters Fill() and Update() methods.

This quote suggests that it is best (or 'good') practice to call any DataBind() methods of Web form controls during the Page_Load event. This might be misleading when designing responses to postbacks (see below).

The code sample in DesignModeSql.aspx worked as expected when EnableViewState was set to false on the DataGrid.

The code samples, by the way, remind us that that DataTable objects have a DefaultView property which may come in handy for runtime enjoyment of filtering and sorting. But for design time declarations, a DataView component is needed.

It may help to mention that the printed code sample that follows this quote is in error. The software code sample (in DesignModeSql.aspx.cs) clearly shows that a PreRender event procedure is required for designing a Sort command. This is because, during a sort postback, the Load event will fire first, then the Sort event procedure and finally the PreRender event procedure. By calling DataBind() during PreRender, the DataGrid object can display the sort applied to its DataView object.

There is no "FindBy" method in the DataSet object. The printed code sample clearly shows that methods with this prefix are generated automatically for the strongly typed dataset, extending the DataSet object. This is an impressive feature!

This quote is in line with the commentary mentioned earlier about the error found in the printed code sample. It follows that DataBind() and Update() methods for controls and datasets respectively is "usually" handled in the PreRender event procedure.

These adapter object properties can be generated at run time with a command builder object: for the SQL Server provider, it's the SqlCommandBuilder object. All the command builder object needs is a SelectCommand object defined in the adapter, using a SQL SELECT statement. Very impressive!

Note that the generated "properties" are not stored in the adapter object. Instead, the command builder object will listen for the adapter's RowUpdating event.

More on the Cache object in Chapter 12.

mod date: 2005-05-03T21:47:43.000Z