新聞中心
這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
ASP.NET中怎么連接SQL數(shù)據(jù)庫(kù)-創(chuàng)新互聯(lián)
這期內(nèi)容當(dāng)中小編將會(huì)給大家?guī)?lái)有關(guān)ASP.NET中怎么連接SQL數(shù)據(jù)庫(kù),文章內(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 的摘要說(shuō)明。///public class WebForm1 : System.Web.UI.Page{private void Page_Load(object sender, System.EventArgs e){// 在此處放置用戶代碼以初始化頁(yè)面Response.Write("第一個(gè)連接數(shù)據(jù)庫(kù)的實(shí)例");SqlConnection myConnection = new SqlConnection("server=localhost;uid=sa;pwd=sa");try{myConnection.Open();//打開數(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);} ////// 設(shè)計(jì)器支持所需的方法 - 不要使用代碼編輯器修改/// 此方法的內(nèi)容。///private void InitializeComponent(){this.Load = new System.EventHandler(this.Page_Load);}#endregion}}
上述就是小編為大家分享的ASP.NET中怎么連接SQL數(shù)據(jù)庫(kù)了,如果剛好有類似的疑惑,不妨參照上述分析進(jìn)行理解。如果想知道更多相關(guān)知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。
本文題目:ASP.NET中怎么連接SQL數(shù)據(jù)庫(kù)-創(chuàng)新互聯(lián)
當(dāng)前鏈接:http://fisionsoft.com.cn/article/hppeh.html