The DataSource control (new in ASP.net) is a real timesaver for programmers. Now, instead of writing all the code to populate a grid, it’s possible to use a DataSource control, a new ‘genre’ (if you will) of controls, which provide ‘declarative’ access to data. Though I won’t go into all of them (there are several – SQL, Access, XML, SiteMapDataSource and ObjectDataSource controls), I will cover the Database type DataControl (SQLDataSource and AccessDataSource). The properties are similar for both.
In general, at the basic level, what happens is that each DataSource control has many properties which the programmer populates, like the ConnectionString property and the SQL statement properties (SelectCommand, UpdateCommand, etc).
Once these properties have been provided, a presentation control (like a GridView, FormView or DetailsView control, all new in v2.0 of the Dotnet Framework) can point to the DataSource control, and without any coding at all – voila – a web page has been created that displays data from a data source. Naturally, it doesn’t do much except presentation, at this point, but like was said earlier, this is just the basic leve..
For the SelectCommand, one can choose a pure SQL Select statement (Select [field name list] from [Table name]), or a Stored Procedure. If a Stored Procedure is used, the ‘SelectCommandType’ property needs to be set thusly:
SelectCommandType="StoredProcedure"
Here, we might add that a new section has been added to the Web.Config file, specifically for Connection Strings. And, as you might figure, the section is called ‘ConnectionStrings’, and is placed inside the Configuration section of the Web.Config file, much like the AppSettings section was used earlier, for the connection strings. The main difference here, is, instead of ‘add key’, we use ‘add name’:
Continues…