Visual Studio 2017(C#)、Microsoft Access 2010搭建ASP.NET网站(页面功能概述一)

一、注册/登录页面

 

1、点击登录按钮:

if 用户名=”” or 密码=”” then

消息提示:用户名或密码不正确


Else

根据所填“用户名”和“密码”查询“用户数据库”

If 查询失败 then

消息提示:该户名不存在,请先进行注册

Else

跳转到数据显示页面


2、点击注册按钮

if 用户名=”” or 密码=”” then

消息提示:用户名或密码不能为空

Else

根据所填“用户名”和“密码”查询“用户数据库”

If 查询失败 then

在数据库插入数据

消息提示:注册成功,可以进行登录

Else

消息提示:该用户已存在,请直接登录或重新注册

注:

1、在asp.net中没有messagebox用法,有的时候在执行某个操作的时候希望能够弹出一些信息框:alert弹出的警告信息框,Response.Write("<script>alert('该用户已存在,请直接登录或重新注册!')</script>")

2、插入记录时,在表名和字段名加[].如:insert into [test]([ID],[password])

完整代码:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Data.OleDb;

 

public partial class 注册页面 : System.Web.UI.Page

{

    protected void Button1_Click(object sender, EventArgs e)

    {

        //登录按钮

        if(username.Text=="" || password.Text=="")

            Response.Write("<script>alert('用户名或密码有误!')</script>");

        else

        {

            string str = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=F:/御用闲人办公网站系统/御用闲人/test.accdb;";

            OleDbConnection OleDbConnection = new OleDbConnection(str);

            OleDbConnection.Open();

         OleDbCommand sqlcmd = new OleDbCommand(@"select * from test where ID='"+this.username.Text +"'and password='"+this.password.Text+"'", OleDbConnection);  //sql语句  

            OleDbDataReader reader = sqlcmd.ExecuteReader();

            if (reader.Read())

            {                

                Response.Redirect("数据显示.aspx");

            }

            else

            {

                Response.Write("<script>alert('该用户不存在,请先进行注册!')</script>");

            }

            OleDbConnection.Close();

        }

    } 

    protected void Button2_Click(object sender, EventArgs e)

    {

        //注册按钮

        if (username.Text == "" || password.Text == "")

            Response.Write("<script>alert('用户名或密码有误!')</script>");

        else

        {

        string str = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=F:/御用闲人办公网站系统/御用闲人/test.accdb;";

            OleDbConnection OleDbConnection = new OleDbConnection(str);

            OleDbConnection.Open();

            OleDbCommand sqlcmd = new OleDbCommand(@"select * from test where ID='" + this.username.Text + "'and password='" + this.password.Text + "'", OleDbConnection);  //sql语句  

            OleDbDataReader reader = sqlcmd.ExecuteReader();

            if (reader.Read())

            {                

                Response.Write("<script>alert('该用户已存在,请重新进行注册或直接登录!')</script>");

            }

            else

            {

              sqlcmd = new OleDbCommand("insert into [test]([ID],[password]) values('" + this.username.Text + "','" + this.password.Text + "')", OleDbConnection);  //sql语句  

                sqlcmd.ExecuteNonQuery();

                Response.Write("<script>alert('注册成功,请进行登录!')</script>");

            }

            OleDbConnection.Close();

        }

    }

}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值