Monday, February 7, 2011

How to Connect asp.net with the database…


Partial Class _Default
    Inherits System.Web.UI.Page

Dim sqlcon As New SqlConnection
Dim sqlcomm As New SqlCommand

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        sqlcon.ConnectionString=ConfigurationManager.AppSettings("connectionstring")
sqlcon.Open()
sqlcomm.Connection = sqlcon
End Sub


And we make a small change on web config file in asp.net
</sectionGroup>
           
      </configSections>

      <appSettings>
            <add key="ConnectionString" value="server=servername;database=databasename;uid=sa;pwd=password"/>
      </appSettings>
     
      <connectionStrings/>
      <system.web>