ADO.NET – The Connected Layer

The data component of the .NET Framework (namely ADO.NET) works with two layers. These layers are called the connected and the disconnected layer. As you can guess, their names refers to the fact whether they are actually connected to a data source.

But before we dig into their details, let’s see what do they have in common – the fundamentals of ADO.NET.

To connect to a data source, your very first step will be to chose a provider. There are four providers built in the .NET Framework 3.5, these are the OleDbProvider, the OdbcProvider, the SqlProvider and the OracleProvider. You typically set the provider in the connectionString section of the web.config. Each provider declares four classes to manipulate data, these are:

  • Command: represents a database command (stored procedure or ad hoc).
  • Connection: represents a database connection. You typically refer to the web.config connectionStrings section to retrieve one.
  • DataReader: provides a read-only, forward-only way to get data from a database.
  • DataAdapter: lets you fill data objects of the disconnected layer, and write back the changes to the database.

Each of these classes gets the prefix of the provider name. So for example, when you want to connect to a SQL database, you will use a SqlConnection class to do so. Let’s take a closer look to these classes:

Continue reading “ADO.NET – The Connected Layer”

Implement a DataSource Control

Implement a DataSource control

We’ll look into the details of the following DataSource controls:

  • AccessDataSource
  • LinqDataSource
  • ObjectDataSource
  • SqlDataSource
  • XmlDataSource

These controls lets you easily bind data to your data-bound controls. You can query, update, delete data sources declaratively with the data source controls. Now let’s take a closer look to these controls:

Continue reading “Implement a DataSource Control”

Data Binding

There will come the time in every web application’s lifetime when it needs to display data. That data will be displayed in ASP.NET controls, but first they need to be bound to that control correctly. In this post we will consider the ways to do so.

There are two types of data-binding: Single-Value Binding and Repeated-Value Binding. Consider the former first.

To bind data to an ASP.NET control which supports it, you use the <%# %> delimiters in the property you want to bind to the data. This happens in the .aspx page, not in the code-behind. Between these delimiters, only valid data binding syntax can occur, for example:

protected string GetUserName()
{
     return User.Identity.Name;
}
<asp:TextBox runat=”server” Text=’<%#GetUserName()%>’/>

Continue reading “Data Binding”