⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 webform1.aspx.cs

📁 希望我上传的购书网站系统能给你很大的帮助
💻 CS
字号:
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 gswz
{
	/// <summary>
	/// WebForm1 的摘要说明。
	/// </summary>
	public class WebForm1 : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.Label Label1;
		protected System.Web.UI.WebControls.Label Label2;
		protected System.Web.UI.WebControls.TextBox TextBox1;
		protected System.Web.UI.WebControls.TextBox TextBox2;
		protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator1;
		protected System.Web.UI.WebControls.HyperLink HyperLink1;
		protected System.Data.SqlClient.SqlConnection sqlConnection1;
		protected System.Data.SqlClient.SqlCommand sqlCommand1;
		protected System.Web.UI.WebControls.ImageButton ImageButton1;
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			// 在此处放置用户代码以初始化页面
			Session["userName"]=null;
		}

		#region Web 窗体设计器生成的代码
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{    
			this.sqlConnection1 = new System.Data.SqlClient.SqlConnection();
			this.sqlCommand1 = new System.Data.SqlClient.SqlCommand();
			this.ImageButton1.Click += new System.Web.UI.ImageClickEventHandler(this.ImageButton1_Click);
			// 
			// sqlConnection1
			// 
			this.sqlConnection1.ConnectionString = "packet size=4096;user id=sa;data source=\"(local)\";persist security info=False;ini" +
				"tial catalog=login";
			// 
			// sqlCommand1
			// 
			this.sqlCommand1.CommandText = "SELECT [user].* FROM [user]";
			this.sqlCommand1.Connection = this.sqlConnection1;
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		private void ImageButton1_Click(object sender, System.Web.UI.ImageClickEventArgs e)
		{
			SqlDataReader sqlDataReader;//定义SQLDataReader对象
			this.sqlCommand1.CommandText="select * from [user] where username='"+this.TextBox1.Text.ToString().Trim()+"'";
			this.sqlConnection1.Open();
			sqlDataReader=this.sqlCommand1.ExecuteReader();
			string password="";
			if(!sqlDataReader.HasRows)
			{
				Response.Write("<script>alert('还没有该用户,请注册!')</script>");
				this.sqlConnection1.Close();
				return;
			}
			if(sqlDataReader.Read())//执行SQLDataReader的Read方法来获取第一个记录 
			{
				password=sqlDataReader.GetString(2).Trim();//获取第三个字段的值
				if(this.TextBox2.Text.Trim()==password)
				{
					Session["userName"]=this.TextBox1.Text;
					Response.Redirect("gift.aspx");
				}
				else
				{
					Response.Write("<script>alert('用户名或密码错误!')</script>");
					return;
				}
			}
			this.sqlConnection1.Close();//关闭连接
		}

	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -