Database
  Home arrow Database arrow Page 2 - ADO.NET 101: SqlDataReader, Part 2
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Mobile Linux 
App Generation ROI 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
DATABASE

ADO.NET 101: SqlDataReader, Part 2
By: Jayaram Krishnaswamy
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 15
    2005-03-21

    Table of Contents:
  • ADO.NET 101: SqlDataReader, Part 2
  • Configuring the Connection to the Database
  • Configuring the Command Object for an SQL Statement
  • Configuring the Command Object for Stored Procedure
  • Stored Procedure that Requires an Input Parameter

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    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.

    More Database Articles
    More By Jayaram Krishnaswamy


     

    DATABASE ARTICLES

    - Database Programming in C# with MySQL : Usin...
    - Formatting Techniques for Data Access from E...
    - Data Access from Excel VBA
    - Generating a Multiple Table Crystal Report u...
    - ADO and the Command Object
    - On Wiring Up an ADO Data Control
    - Reading and Writing to Files on the Intranet
    - Using ADO Record to Create and Navigate Intr...
    - Using Data Access Pages to Access Data on a ...
    - Using ADO with the SQL Native Client
    - ADO`s Stream Object
    - Opening a Record Object Referencing an Open ...
    - Introducing Jasper (SQL Anywhere 10 Beta)
    - Creating a Database Project in VS 2005
    - Manipulating ADO Recordsets





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
    Stay green...Green IT