Python语言技术文档

微信小程序技术文档

php语言技术文档

jsp语言技术文档

asp语言技术文档

C#/.NET语言技术文档

html5/css技术文档

javascript

点击排行

您现在的位置:首页 > 技术文档 > C#/.NET技巧

ASP.NET连接SQL数据库的简单实例代码

来源:中文源码网    浏览:122 次    日期:2024-05-11 12:06:47
【下载文档:  ASP.NET连接SQL数据库的简单实例代码.txt 】


ASP.NET连接SQL数据库的简单实例代码
复制代码 代码如下: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}}

相关内容