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