這期內(nèi)容當(dāng)中小編將會給大家?guī)碛嘘P(guān)ASP.NET中怎么連接SQL數(shù)據(jù)庫,文章內(nèi)容豐富且以專業(yè)的角度為大家分析和敘述,閱讀完這篇文章希望大家可以有所收獲。
代碼如下:
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("第一個連接數(shù)據(jù)庫的實例");SqlConnection myConnection = new SqlConnection("server=localhost;uid=sa;pwd=sa");try{myConnection.Open();//打開數(shù)據(jù)庫鏈接Response.Write("鏈接成功!");}catch{Response.Write("鏈接失?。?);}} #region Web 窗體設(shè)計器生成的代碼override protected void OnInit(EventArgs e){//// CODEGEN: 該調(diào)用是 ASP.NET Web 窗體設(shè)計器所必需的。//InitializeComponent();base.OnInit(e);} ////// 設(shè)計器支持所需的方法 - 不要使用代碼編輯器修改/// 此方法的內(nèi)容。///private void InitializeComponent(){this.Load = new System.EventHandler(this.Page_Load);}#endregion}}
上述就是小編為大家分享的ASP.NET中怎么連接SQL數(shù)據(jù)庫了,如果剛好有類似的疑惑,不妨參照上述分析進(jìn)行理解。如果想知道更多相關(guān)知識,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。