//后台代码
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnOK_Click(object sender, EventArgs e)
{
string str = ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString; //连接数据库,在webconfig中配置
SqlConnection Conn = new SqlConnection(str);
Conn.Open();
string sql = "select * from Table_User where UserName=@UserName and PassWord=@PassWord" ;
SqlCommand Comm = new SqlCommand(sql, Conn);
Comm.Parameters.Add("UserName",TextBox1.Text);
Comm.Parameters.Add("PassWord",TextBox2.Text);
SqlDataReader sdr = Comm.ExecuteReader();
if (sdr.Read())
{
Session["UserName"] = TextBox1.Text;
Session["PassWord"] = TextBox2.Text;
Label1.Text = "登陆成功!";