ASP.NET數(shù)據(jù)庫(kù)連接實(shí)例淺析
作者:佚名 
  ASP.NET數(shù)據(jù)庫(kù)連接是如何實(shí)現(xiàn)的呢?那么本文就將向你介紹ASP.NET數(shù)據(jù)庫(kù)連接的實(shí)例實(shí)現(xiàn),希望對(duì)你有所幫助。
 ASP.NET數(shù)據(jù)庫(kù)連接實(shí)例展現(xiàn):
- using System;
 - using System.Collections;
 - using System.ComponentModel;
 - using System.Data;
 - using System.Drawing;
 - using System.Web;
 - using System.Web.SessionState;
 - using System.Web.UI;
 - using System.Web.UI.WebControls;
 - using System.Web.UI.HTMLControls;
 - using System.Data.SqlClient;
 - namespace Example01
 - {
 - ///
 - /// WebForm1 的摘要說(shuō)明。
 - ///
 - public class WebForm1 : System.Web.UI.Page
 - {
 - private void Page_Load(object sender, System.EventArgs e)
 - {
 - // 在此處放置用戶代碼以初始化頁(yè)面
 - Response.Write("
 - ***個(gè)ASP.NET數(shù)據(jù)庫(kù)連接的實(shí)例
 - ");
 - SqlConnection myConnection = new SqlConnection("server=localhost;uid=sa;pwd=sa");
 - try
 - {
 - myConnection.Open();//打開(kāi)數(shù)據(jù)庫(kù)鏈接
 - Response.Write("鏈接成功!");
 - }
 - catch
 - {
 - Response.Write("鏈接失?。?);
 - }
 - }
 - #region Web 窗體設(shè)計(jì)器生成的代碼
 - override protected void OnInit(EventArgs e)
 - {
 - //
 - // CODEGEN: 該調(diào)用是 ASP.NET Web 窗體設(shè)計(jì)器所必需的。
 - //
 - InitializeComponent();
 - base.OnInit(e);
 - }
 - ///
 - /// ASP.NET數(shù)據(jù)庫(kù)連接之設(shè)計(jì)器支持所需的方法 - 不要使用代碼編輯器修改
 - /// 此方法的內(nèi)容。
 - ///
 - private void InitializeComponent()
 - {
 - this.Load += new System.EventHandler(this.Page_Load);
 - }
 - #endregion
 - }
 - }
 
ASP.NET數(shù)據(jù)庫(kù)連接的實(shí)例就向你介紹到這里,希望對(duì)你有所幫助。
【編輯推薦】
責(zé)任編輯:仲衡 
                    來(lái)源:
                    星光下載
 














 
 
 
 
 
 
 