ASP.NET
  Home arrow ASP.NET arrow Page 4 - Creating a StudentDB Class for ASP.NET 2.0
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? 
ASP.NET

Creating a StudentDB Class for ASP.NET 2.0
By: Michael Youssef
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 15
    2007-09-05

    Table of Contents:
  • Creating a StudentDB Class for ASP.NET 2.0
  • Creating the Website and the App_Code Folder
  • Writing the Student class
  • Storing the Connection String in a Web.Config file
  • The StudentDB class

  • 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


    Creating a StudentDB Class for ASP.NET 2.0 - Storing the Connection String in a Web.Config file


    (Page 4 of 5 )

    New in ASP.NET 2.0 is the <connectionStrings> element, or we could say section, in the web.config file. You can add connection strings as child elements to the <connectionStrings> element as in the following code:

    <connectionStrings>
      <add name="SchoolConnectionString"
    connectionString="Data Source=(local);Initial
    Catalog=School;Integrated Security=True"
    providerName="System.Data.SqlClient"/>
    </connectionStrings>

    You need to put this <connectionStrings> element in the Web.Config file of the website. To do that, right click on the website in Solution Explorer; right click then select Add New Item, select Web Configuration File and leave its default name as shown in the following screenshot:

    Click on add; now open the Web.Config file and locate the element <connectionStrings /> and replace it with the one above. Note that we have used the child element <add> in order to add a connection string to the Web.Config. The name attribute denotes the name that will be used in code to refer to that particular connection string. The connection string itself is added using the connectionString attribute.

    Please, if you are not familiar with ADO.NET, you must read about it before you proceed. I have written many articles about ADO.NET objects covering SqlConnection, SqlCommand and SqlDataReader. These will give you an understanding of how to work with ADO.NET.

    To retrieve the connection string from the C# code you need the following line of code:

    WebConfigurationManager.ConnectionStrings
    ["SchoolConnectionString"].ConnectionString;

    The WebConfigurationManager class has a property called ConnectionStrings that is used to retrieve the connection string from the configuration file. This property is of type ConnectionStringSettingsCollection so we use the indexer syntax to access its individual objects which are of type ConnectionStringSettings. We get the connection string itself through the use of the ConnectionStringSettings.ConnectionString property. This article is not about configuring ASP.NET applications so I will not spend the time to talk about the Web.Config file; please consult other articles on this topic. We will write the above line in the StudentDB C# class in the next section.

    More ASP.NET Articles
    More By Michael Youssef


       · i haven't developed any real projects before because i still learning C# and asp.net...
       · Hi, Of course, you can read the article. It's not that difficult if you have...
       · A very good explanation, I visited ASP.net for first time and i find the very first...
       · Thanks, the next 2 article will be interesting more than this one. You will...
       · Very good article and can't wait for the second and third parts. are you going to...
       · Very good article and can't wait for the second and third parts. are you going to...
       · You will like the following articles even more.About the SqlDataSource control, I...
       · Nice article Michael but I need the other articles to complete the class. when we...
       · You will be reading the articles in the next few weeks. Tell me what do you think...
       · If you have an idea about an article related to ASP.NET 2.0 Data Access, please send...
       · Don't get me wrong the article is interesting. However, since it is broken in...
     

    ASP.NET ARTICLES

    - Developing a Mini ASP.NET AJAX Server Centri...
    - Disadvantages of the ASP.NET MVC Framework
    - Advantages of the ASP.NET MVC Approach
    - ASP.NET Web Forms Weaknesses
    - ASP.NET Web Forms Meets ASP.NET MVC
    - Source Code for Saving and Retrieving Data w...
    - Using GridView to Save and Retrieve Data wit...
    - Handling Dynamic Images in ASP.NET 3.5 AJAX ...
    - Retrieving Data with AJAX and the GridView C...
    - Playing with Images in ASP.NET 3.5 AJAX Appl...
    - Saving and Retrieving Data with AJAX
    - Enhancing PHP Via the ASP.NET AJAX Framework...
    - Enhancing PHP Programming with the ASP.NET A...
    - Classes and ASP.NET AJAX
    - Using ASP.NET AJAX

     
    Best Practices for Windows Vista Migration Presentation
    Dell and Microsoft recently held a series of face-to-face seminars entitled, &qu....

     
    Creating a Culture for Code Reuse
    If you oversee development teams you know that like it or not proprietary and ex....

     
    Keys to Web Application Acceleration: Advances in Delivery Systems
    Accelerate Web apps by up to 5x. Ensure significantly faster access to the Web a....

     
    Optimizing Application Monitoring
    Tired of finding out from your customers that you're offline? This white paper e....

     
    Solaris to Solaris Migration -- Migrating applications from Sun SPARC to Dell PowerEdge R900
    This comprehensive Migration Guide reviews the approach that Principled Technolo....

     




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