CoolInterview.com - World's Largest Collection of Interview Questions
 Interview Questions  
 Our Services  

Get 9,000 Interview Questions & Answers in an eBook.


  • 9500+ Pages
  • 9000 Question & Answers
  • All Tech. Categories
  • 14 MB Content

    Get it now !!


    Send your Resume to 6000 Companies


  • INTERVIEW QUESTIONS MICROSOFT ASP.NET 2.0 DETAILS
    Question :
    How to create a DB connection at one place/page so that we can use that connection for all pages/forms/windows.what r the steps ned to be performed.
    if question not clear,let me know.

    Category ASP.NET 2.0 Interview Questions
    Rating (4.0) By 1 users
    Added on 7/28/2006
    Views 752
    Rate it!
    Answers:

    <?xml version="1.0" encoding="utf-8" ?>
    <!-- Web.Config Configuration File -->
    <configuration>
    <appSettings>
    <add key="ConnectionString"
    value="server=localhost;database=Northwind;uid=sa;password=secret;" />
    </appSettings>
    <system.web>
    <customErrors mode="Off"/>
    </system.web>
    </configuration>

    Imports System
    Imports System.Web
    Imports System.Web.UI
    Imports System.Web.UI.WebControls
    Imports System.Data
    Imports System.Data.SqlClient
    Imports System.Configuration

    Public Class ConnString : Inherits Page

    Protected dataGrid As DataGrid

    Protected Sub Page_Load(ByVal Sender As Object, ByVal E As EventArgs)
    Dim sqlConn As SqlConnection
    Dim sqlCmd As SqlCommand
    Dim strConnection As String

    Try
    'Get connection string from Web.Config
    strConnection = ConfigurationSettings.AppSettings("ConnectionString")
    sqlConn = New SqlConnection(strConnection)
    sqlCmd = New SqlCommand("SELECT * FROM Customers WHERE " _
    & "(CompanyName LIKE 'A%') OR (CompanyName LIKE 'B%')", sqlConn)
    sqlConn.Open()
    dataGrid.DataSource = sqlCmd.ExecuteReader()
    dataGrid.DataBind()
    Catch ex As Exception
    Response.Write(ex.ToString & "<br>")
    Finally
    sqlConn.Close()
    End Try
    End Sub

    End Class





    If you have the better answer, then send it to us. We will display your answer after the approval.
    Name :*
    Email Id :*
    Answer :*
    Verification Code Code Image - Please contact webmaster if you have problems seeing this image code Not readable? Load New Code
    Process Verification  Enter the above shown code:*
    Inform me about updated answers to this question

       
    Related Questions
    View Answer
    What is IPostBack? How to use it?
    View Answer
    What is server infrastructure & Server components?
    View Answer
    What is event bubbling?
    View Answer
    Which dll handles the request of .aspx page?
    View Answer
    How to reduce the width of textbox in EditCommandColumn of DataGrid?
    View Answer
    If we remove web.config or machine.config from the application
    then, Is this application will works?
    View Answer
    List of Words of PreProcessor in .NET?
    View Answer
    Please brief not about XSD,XSLT & XML.
    View Answer
    What is PreProcessor in .NET and type , where it use
    View Answer
    How to create dynamic Gridview?

    View Answer

    Please Note: We keep on updating better answers to this site. Subscribe to our newsletter to get notified when better answer is posted.

    Notify me when better answer is posted!
    Email:

    View ALL ASP.NET 2.0 Interview Questions

    User Options
    Sponsored Links


    Copyright ©2003-2009 CoolInterview.com, All Rights Reserved.
    Privacy Policy | Terms and Conditions
    Page URL: http://www.coolinterview.com/interview/8787/default.asp?cachecommand=bypass


    Download Yahoo Messenger | Placement Papers| FREE SMS | ASP .Net Tutorial | Web Hosting | Dedicated Servers | Joke of the Day

    0.42