using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Web.Configuration;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
private string getConnectionString()
{
return WebConfigurationManager.ConnectionStrings["users"].ConnectionString;
}
protected void Button1_Click(object sender, EventArgs e)//注册
{
using (SqlConnection connection = new SqlConnection(getConnectionString()))
{
string queryString = "insert into [dbo].[Table_1] (username,password) values('" + TextBox1.Text + "','" + TextBox2.Text + "')";
SqlCommand command = new SqlCommand();
command.Connection = connection;
command.CommandType = CommandType.Text;
command.CommandText = queryString;
connection.Open();
command.ExecuteNonQuery();
}
}
protected void Button2_Click(object sender, EventArgs e) //登录
{
using (SqlConnection connection = new SqlConnection(getConnectionString()))
{
string queryString = "select * from [dbo].[Table_1] where username='" + TextBox1.Text.ToString() + "' and password='" + TextBox2.Text.ToString() + "'";
SqlCommand command = new SqlCommand();
command.Connection = connection;
command.CommandType = CommandType.Text;
command.CommandText = queryString;
connection.Open();
SqlDataReader reader = command.ExecuteReader();
if (reader.Read())
{
Response.Write("<script>alert('登录传成功')</script>");
}
else
{
Response.Write("<script>alert('登录传失败')</script>");
}
}
}
protected void Button3_Click(object sender, EventArgs e)//修改密码
{
using (SqlConnection connection = new SqlConnection(getConnectionString()))
{
string queryString = "update [dbo].[Table_1] set username= '" + TextBox1.Text + "' ,password= '" + TextBox2.Text + "'";
SqlCommand command = new SqlCommand();
command.Connection = connection;
command.CommandType = CommandType.Text;
command.CommandText = queryString;
connection.Open();
command.ExecuteNonQuery();
}
}
protected void Button4_Click(object sender, EventArgs e)
{
using (SqlConnection connection = new SqlConnection(getConnectionString()))
{
string queryString = "delete from [dbo].[Table_1] where username= '" + TextBox1.Text + "'";
SqlCommand command = new SqlCommand();
command.Connection = connection;
command.CommandType = CommandType.Text;
command.CommandText = queryString;
connection.Open();
command.ExecuteNonQuery();
}
}
}
ASP.NET实现简单的登录,注册,修改密码,注销等功能
最新推荐文章于 2022-04-21 23:54:04 发布