展开全部
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data;
using System.Data.SqlClient;
namespace asp.net
{
public partial class _Default : System.Web.UI.Page
{
//连接数据库文件
SqlConnection conn = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename='i:\我的文档\My Documents\Visual Studio 2008\Projects\asp.net课程作业\asp.net课程作业\App_Data\User.mdf';Integrated Security=True;User Instance=True");
protected void Page_Load(object sender, EventArgs e)
{
}
//从数据库中查询用户数据函数
public void CheckUser()
{
SqlCommand cmd =new SqlCommand("select * from [User] where ID=2008");
cmd.Connection = conn;
conn.Open();
SqlDataReader sdr = cmd.ExecuteReader();
if (sdr.Read())
{
TextBox1.Text = sdr["ID"].ToString();
TextBox2.Text = sdr["name"].ToString();
TextBox3.Text = sdr["age"].ToString();
}
sdr.Close();
}
protected void Button1_Click(object sender, EventArgs e)
{
CheckUser();
conn.Close();
}
protected void Button2_Click(object sender, EventArgs e)
{
TextBox1.Text = "";
TextBox2.Text = "";
TextBox3.Text = "";
}
}
}
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data;
using System.Data.SqlClient;
namespace asp.net
{
public partial class _Default : System.Web.UI.Page
{
//连接数据库文件
SqlConnection conn = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename='i:\我的文档\My Documents\Visual Studio 2008\Projects\asp.net课程作业\asp.net课程作业\App_Data\User.mdf';Integrated Security=True;User Instance=True");
protected void Page_Load(object sender, EventArgs e)
{
}
//从数据库中查询用户数据函数
public void CheckUser()
{
SqlCommand cmd =new SqlCommand("select * from [User] where ID=2008");
cmd.Connection = conn;
conn.Open();
SqlDataReader sdr = cmd.ExecuteReader();
if (sdr.Read())
{
TextBox1.Text = sdr["ID"].ToString();
TextBox2.Text = sdr["name"].ToString();
TextBox3.Text = sdr["age"].ToString();
}
sdr.Close();
}
protected void Button1_Click(object sender, EventArgs e)
{
CheckUser();
conn.Close();
}
protected void Button2_Click(object sender, EventArgs e)
{
TextBox1.Text = "";
TextBox2.Text = "";
TextBox3.Text = "";
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询