ASP.NET实现简单的登录,注册,修改密码,注销等功能

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();
        }
    }
}

https://blog.csdn.net/weixin_42371928/article/details/90551148?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-2.channel_param&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-2.channel_param

  • 2
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值