1、public class UserInfoprivate string userName;private string passWord;private string xingMing;private string age;public string UserNameget return userName; set userName = value; public string PassWordget return passWord; set passWord = value; public string XingMingget return xingMing; set xingMing =
2、value; public string Ageget return age; set age = value; public class DBHelperprivate static string connectionString = “Server=I6R7IVUNHOKLYSD;Database= DBUser;Trusted_connection=SSPI“;public static SqlDataReader ExecuteReader(string strSql)SqlConnection con = new SqlConnection(connectionString);Sql
3、Command cmd = new SqlCommand(strSql, con);trycon.Open();SqlDataReader myReader = cmd. ExecuteReader(CommandBehavior.CloseConnection);return myReader;catch (System.Data.SqlClient.SqlException e)throw e;public static DataSet Query(string SQLString)using (SqlConnection connection = new SqlConnection(co
4、nnectionString)DataSet ds = new DataSet();tryconnection.Open();SqlDataAdapter command = new SqlDataAdapter(SQLString, connection);command.Fill(ds, “ds“);catch (System.Data.SqlClient.SqlException ex)throw new Exception(ex.Message);return ds;public partial class Login : System.Web.UI.Pageprotected voi
5、d Page_Load(object sender, EventArgs e)lblTishi.Text = string.Empty;protected void btnOk_Click(object sender, EventArgs e)string sql = string.Format(“select * from UserInfo where UserName=0 and PassWord=1“, txtName.Text, txtMm.Text);UserInfo us = getUser(sql);if (us != null)Session“user“ = us;Respon
6、se.Redirect(“Main.aspx“);elselblTishi.Text = “用户名或密码出错“;protected UserInfo getUser(string sql)UserInfo us = null;SqlDataReader myReader = DBHelper.ExecuteReader(sql);if (myReader.Read()us = new UserInfo();us.UserName = myReader“UserName“.ToString();us.PassWord = myReader“PassWord“.ToString();us.Xing
7、Ming = myReader“XingMing“.ToString();us.Age = myReader“Age“.ToString();return us;protected void btnClear_Click(object sender, EventArgs e)txtName.Text = string.Empty;txtMm.Text = string.Empty;public partial class Main : System.Web.UI.Pageprotected void Page_Load(object sender, EventArgs e)if (Sessio
8、n“user“ != null)UserInfo us = (UserInfo)Session“user“;lblMessage.Text = us.XingMing;elseResponse.Redirect(“Login.aspx“);protected void btnOut_Click(object sender, EventArgs e)Response.Redirect(“Login.aspx“);public partial class UserInform : System.Web.UI.Pageprotected void Page_Load(object sender, E
9、ventArgs e)if(!IsPostBack)string sql=string.Format(“select * from UserInfo order by sort“);bindDataGridView(sql);protected void btnRet_Click(object sender, EventArgs e)string sql=string.Format(“select * from UserInfo where XingMing like %0%“,txtName.Text.Trim();bindDataGridView(sql);protected void bindDataGridView(string sql)DataTable dt=DBHelper.Query(sql).Tables0;if(dt!=nullGridView1.DataBind();