编辑: 夸张的诗人 | 2019-07-09 |
packet size=4096;
user id=sa;
data source=YANGHT;
persist security info=False;
initial catalog=Test );
MyConnection.Open ();
//构造SQL语句,该语句在Users表中检查用户名和密码是否正确 string mysql= select * from [User] where UserName='
+Login_name.Text + '
and PassWord='
+Login_password.Text + '
;
//创建Command对象 SqlCommand cm=new SqlCommand (mysql,MyConnection);
//执行ExecuteReader ()方法 SqlDataReader dr=cm.ExecuteReader();
if(dr.Read ()) { lbl_message.Text= ;
//保存当前用户名及用户权限 Session[ dlname ]=dr[ dlname ].ToString ();
Session[ type ]=dr[ type ].ToString ();
Response.Redirect ( index.htm );
if(Session[ type ].ToString ()==
0 ) { //系统管理员身份登入界面 Response.Redirect ( TestMT.aspx );
} } else { lbl_message.Text = 用户名或者密码不正确,请重新输入 ;
} //关闭连接 MyConnection.Close();
} private void Login_reset_Click(object sender, System.EventArgs e) { Login_name.Text= ;
Login_password.Text= ;
lbl_message.Text = ;
} } } 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;
namespace test { /// /// Test 的摘要说明. /// public class Test : System.Web.UI.Page { protected System.Web.UI.WebControls.DataGrid DataGrid1;
protected System.Web.UI.WebControls.Button btAdd;
protected System.Web.UI.WebControls.TextBox tbID;
protected System.Web.UI.WebControls.TextBox tbCourse;
protected System.Web.UI.WebControls.TextBox tbType;
protected System.Web.UI.WebControls.TextBox tbKey;
protected System.Web.UI.WebControls.TextBox tbRemark;
protected System.Web.UI.WebControls.Button btQuery;
protected System.Web.UI.WebControls.Button btDelete;
private void Page_Load(object sender, System.EventArgs e) { // 在此处放置用户代码以初始化页面 } #region Web 窗体设计器生成的代码 override protected void OnInit(EventArgs e) { // // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的. // InitializeComponent();
base.OnInit(e);
} /// /// 设计器支持所需的方法 - 不要使用代码编辑器修改 /// 此方法的内容. /// private void InitializeComponent() { this.btAdd.Click += new System.EventHandler(this.btAdd_Click);
this.btDelete.Click += new System.EventHandler(this.btDelete_Click);
this.btQuery.Click += new System.EventHandler(this.btQuery_Click);
this.Load += new System.EventHandler(this.Page_Load);
........