国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

ASP.NET連接SQL數據庫的簡單實例代碼

2024-07-10 12:44:55
字體:
來源:轉載
供稿:網友

代碼如下:
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("第一個連接數據庫的實例");
SqlConnection myConnection = new SqlConnection("server=localhost;uid=sa;pwd=sa");
try
{
myConnection.Open();//打開數據庫鏈接
Response.Write("鏈接成功!");
}
catch
{
Response.Write("鏈接失敗!");
}
}

#region Web 窗體設計器生成的代碼
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 該調用是 ASP.NET Web 窗體設計器所必需的。
//
InitializeComponent();
base.OnInit(e);
}

///
/// 設計器支持所需的方法 - 不要使用代碼編輯器修改
/// 此方法的內容。
///
private void InitializeComponent()
{
this.Load = new System.EventHandler(this.Page_Load);
}
#endregion
}
}

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 英山县| 平远县| 易门县| 即墨市| 政和县| 瓮安县| 泾川县| 东安县| 子长县| 新乐市| 临城县| 兴安盟| 长岛县| 苏尼特左旗| 湘西| 华池县| 广河县| 德江县| 伊川县| 西盟| 义马市| 高尔夫| 遂平县| 孟连| 安国市| 满洲里市| 海安县| 临澧县| 榆中县| 出国| 汾西县| 永济市| 河曲县| 民勤县| 拜城县| 安化县| 黄大仙区| 双柏县| 连云港市| 塔城市| 秦皇岛市|