This article is one in a series of articles on ASP. NET 1.x, you'd need to write code to: While only five to ten lines of code is needed to perform these four steps, and libraries like the Data Access Application Block help reduce the volume of code that you need to write, the fact remains that in order to access or modify data in an ASP. In this article we'll be examining how to access data from databases with the Sql Data Source and Access Data Source controls.
Regardless of where your database is located, once you have a database to work with in order to access its contents you'll want to add a Sql Data Source (or Access Data Source) control to the page. The Data Source controls display in the Designer as a little gray box; they do not emit any HTML markup when a browser visits the page.
In order to correctly access data, we must set a variety of Sql Data Source properties that indicate the database to use and the query to execute.
(True, you have to provide a connection string rather than simply the path to the file, but Visual Studio 2005 can automatically create appropriate connection strings for those databases residing in your folder.) In this article we'll examine the Sql Data Source in detail, just touching upon the one difference in the Access Data Source.
Furthermore, the Sql Data Source and Access Data Source controls can be used to both access and modify data; however, this article only examines accessing data.
We'll see how to use these Data Source controls to modify database data in a future installment.
Also, we'll focus on working with these Data Source controls in Visual Studio 2005 through the Design view.
While these can be set through the Properties pane, it's usually quicker to use the wizard, which can be reached by clicking on the "Configure Data Source" link in the Sql Data Source control's smart tag.
When you click the "Configure Data Source" link a wizard appears, prompting you to select the data to retrieve.
While you can set all of these properties by hand in the Source view, the Design view offers a time-saving wizard for quickly specifying which database to connect to and what query to issue.