ADO.NET 101: SqlDataReader, Part 2 - Configuring the Connection to the Database
(Page 2 of 5 )
Create a new ASP.NET Web application which adds the default WebForm1.aspx to the project. From the ToolBox->Data, drag an SQLConnection Control to the design pane of the WebForm1.aspx. This will add an instance SQLConnection1 of SqlConnection to the tray below the design pane. Right clicking this control will reveal its properties as shown in this picture.

Clicking on the empty space by the item ConnectionString will reveal the handle for the drop-down. Clicking on this handle pops up a drop-down list containing the existing SQLConnections as well as an option to make a new connection, if necessary, as seen in the above picture. You can see that there are four connections on the server XPHTEK(local), and a remote connection (Nechost). This sets up the ConnectionString necessary for the application to connect to the SQL Server.
There are other ways of making an SQLConnection. Please refer to this article for details: http://www.codeproject.com/aspnet/SQLConnect.asp
Adding and Configuring a SQLCommand Object Adding a SQLCommand is as easy as adding the SQLConnection. Simply drag the SQLCommand Control from Toolbox->Data and drop it on the design pane and an instance of this object, SQLCommand1 will make its way to the tray alongside the SQLConnection1.

The very first thing to do after adding an instance of SQLCommand is to set its Connection property. In order to do this, right click this control to view its properties as shown in the next picture. When newly added the item Connection will be showing none. Clicking inside this item pops up a drop-down list, where one could make a new connection or use an existing connection. To use an existing connection, just expand the item by clicking on the + sign.

As discussed in Part 1, the next property of the SQLCommand to be set is its CommandType property. Notice that the Connection is pointing to the SQLConnection1 instance created in the earlier step. For the native SQLConnection chosen there are basically two possible settings for CommandType property. It could be either the type Text, or the type Stored Procedure. The third option (TableDirect) is not supported by the SQL Native Data Provider. By clicking on the empty space in the CommandType line, one of these choices can be made.

Next: Configuring the Command Object for an SQL Statement >>
More Database Articles
More By Jayaram Krishnaswamy