<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table>
<tr>
<td> <asp:Label ID="Label1" runat="server" Text="用户名:"></asp:Label> </td>
<td> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td> <asp:Label ID="Label2" runat="server" Text="密码:"></asp:Label> </td>
<td> <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td><asp:Button ID="Button2" runat="server" Text="登录" onclick="Button2_Click" /> </asp:Label> </td>
<td> <asp:Button ID="Button1" runat="server" Text="注册" onclick="Button1_Click" /> </asp:TextBox></td>
</tr>
</table>
</div>
</form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data; namespace WebApplication1
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ }
//登录
protected void Button2_Click(object sender, EventArgs e)
{
string name = TextBox1.Text;
string pwd = TextBox2.Text;
if (name!=null||pwd!=null)
{
string sql = "select count(0) from student where stuName=@a and stuNo=@b";//获取数据中的信息
SqlParameter p1 = new SqlParameter("@a",name);
SqlParameter p2 = new SqlParameter("@b",pwd);
//连接数据库
string connStr = "server=DESKTOP-QQGOIKH;uid=sa;pwd=123;database=stuDB";
SqlConnection conn = new SqlConnection(connStr);
conn.Open();
SqlCommand cmd = new SqlCommand(sql,conn);
cmd.Parameters.Add(p1);
cmd.Parameters.Add(p2);
object obj = cmd.ExecuteScalar();
conn.Close();
int i = (int)obj;
if (i>)
{
Response.Redirect("WebForm2.aspx");
}
else
{
Response.Write("登录失败");
}
}
else
{
return;
} }
//注册
protected void Button1_Click(object sender, EventArgs e)
{
Response.Redirect("WebForm3.aspx"); }
}
}
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm3.aspx.cs" Inherits="WebApplication1.WebForm3" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table>
<tr>
<td><asp:Label ID="Label1" runat="server" Text="用户名:"></asp:Label> </td>
<td> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td><asp:Label ID="Label2" runat="server" Text="密码:"></asp:Label> </td>
<td><asp:TextBox ID="TextBox2" runat="server"></asp:TextBox> </td>
</tr>
<tr>
<td> <asp:Button ID="Button1" runat="server" Text="注册" onclick="Button1_Click" /> </td>
<td> <asp:Button ID="Button2" runat="server" Text="返回" onclick="Button2_Click" /> </td>
</tr>
</table>
</div>
</form>
</body>
</html>
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; namespace WebApplication1
{
public partial class WebForm3 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ }
//注册
protected void Button1_Click(object sender, EventArgs e)
{
string name = TextBox1.Text;
string pwd = TextBox2.Text;
if (name!=null||pwd!=null)
{
string sql = "insert into enter values(@a,@b)";
SqlParameter[] sp = new SqlParameter[];
sp[] = new SqlParameter("@a",TextBox1.Text);
sp[] = new SqlParameter("@b",TextBox2.Text);
SqlConnection conn = new SqlConnection("server=STER-PC;uid=sa;pwd=123;database=t2");
conn.Open();
SqlCommand comm = new SqlCommand(sql,conn);
comm.Parameters.AddRange(sp);//添加数组
int i = comm.ExecuteNonQuery();
conn.Close();
if (i>)
{
Response.Write("注册成功");
}
else
{
Response.Write("注册失败");
}
}
else
{
Response.Write("请填写内容");
}
}
//返回
protected void Button2_Click(object sender, EventArgs e)
{
Response.Redirect("WebForm1.aspx");
}
}
}

ASP.NET简单登录注册实例的更多相关文章

  1. tornado 08 数据库-ORM-SQLAlchemy-表关系和简单登录注册

    tornado 08 数据库-ORM-SQLAlchemy-表关系和简单登录注册 引言 #在数据库,所谓表关系,只是人为认为的添加上去的表与表之间的关系,只是逻辑上认为的关系,实际上数据库里面的表之间 ...

  2. Node.js_express_中间件 middleware_登录/注册实例源代码

    静态资源: 都写死了的资源,如 css,html 解析规则: 所有路由和中间件都在一个数组中,js 引擎会按照代码先后顺序添加路由和中间件 当请求发送到服务器时,服务器获取当前的请求信息(请求方式.请 ...

  3. 简单登录注册实现(Java面向对象复习)

    简单登录注册的实现(面向对象的复习) 需求: 设计用户类,包含用户名和密码两个属性 设计LoginDemo类设计用户登录方法 用户有三次登录机会,如果连续三次登录失败则退出程序 功能实现页面:     ...

  4. Vue学习之路之登录注册实例代码

    Vue学习之路之登录注册实例代码:https://www.jb51.net/article/118003.htm vue项目中路由验证和相应拦截的使用:https://blog.csdn.net/wa ...

  5. vue-cli——vue-resource登录注册实例

    前言 使用vue-resource请求接口非常方便,在使用前需安装vue-resource依赖并在入口文件main.js中声明. 实例功能简述 本实例只有简单的两个模块:登录和注册,主要演示如何用vu ...

  6. Struts2开发环境搭建,及一个简单登录功能实例

    首先是搭建Struts2环境. 第一步 下载Struts2去Struts官网 http://struts.apache.org/ 下载Struts2组件.截至目前,struts2最新版本为2.3.1. ...

  7. MVC+三层+ASP.NET简单登录验证

    通过制作一个登录小案例来搭建MVC简单三层 在View --Shared下创建一个母版页: <!DOCTYPE html> <html> <head> <me ...

  8. tornado框架基础08-sqlalchemy表关系和简单登录注册

    01 一对一表关系 Module 需要先创建对应的 Module ,这里采用之前建立好的 User 和 UserDetails relationship from sqlalchemy.orm imp ...

  9. flask简单登录注册

    效果图 发布问答页面需要登录才能访问,没有登录会跳转到登录页面 模板继承,正则验证,数据库迁移,md5加密 mysql 5.7 登录页面 登录后的发布问答页面,右上角会显示用户名和注销 项目代码:码云

随机推荐

  1. sql 表连接 join

    inner join  和  join  的 区别 inner join 是内连接 ,查询出两边 都有的数据 join  是交叉 连接, 假设集合A={a, b},集合B={0, 1, 2},则两个集 ...

  2. CCS3属性之text-overflow:ellipsis;的用法和注意之处

    语法: text-overflow:clip | ellipsis 默认值:clip 适用于:所有元素 clip: 当对象内文本溢出时不显示省略标记(...),而是将溢出的部分裁切掉. ellipsi ...

  3. [Ubuntu] Install subversion1.8 on Ubuntu13.10

    Subversion1.8 is difference far away from subversion1.7, here is the steps to install subversion1.8. ...

  4. 【DP水题】投票问题(二)

    投票问题(一) [试题描述] 欧阳文和欧阳武竞选学联主席,汪梁森负责唱票,共有m+n张,结果欧阳文获胜,已知欧阳文和欧阳武分别获得 m 张票和 n 张票(m>n).现在请你计算在唱票过程中欧阳文 ...

  5. pycharm常用快捷键

    Alt+Enter 自动添加包Ctrl+t SVN更新Ctrl+k SVN提交Ctrl + / 注释(取消注释)选择的行Ctrl+Shift+F 高级查找Ctrl+Enter 补全Shift + En ...

  6. 基于mjpg_streamer视频服务器移植【转】

    本文转载自:http://blog.csdn.net/wavemcu/article/details/7539560 MJPG简介: MJPG是MJPEG的缩写,但是MJPEG还可以表示文件格式扩展名 ...

  7. ASP.NET MVC下的四种验证编程方式【转】

    ASP.NET MVC采用Model绑定为目标Action生成了相应的参数列表,但是在真正执行目标Action方法之前,还需要对绑定的参数实施验证以确保其有效 性,我们将针对参数的验证成为Model绑 ...

  8. BAT 批处理脚本 教程

    第一章 批处理基础第一节 常用批处理内部命令简介 批处理定义:顾名思义,批处理文件是将一系列命令按一定的顺序集合为一个可执行的文本文件,其扩展名为BAT或者CMD.这些命令统称批处理命令.小知识:可以 ...

  9. listview 滑动以后设置最上面一行为整行展示

    需求: listview显示的第一行永远为整行,不能为半行. 参考: android listview 每次滑动整行 1. 添加 listview 的 setOnScrollListener() 事件 ...

  10. ARM多核处理器启动过程分析【转】

    转自:http://blog.csdn.net/qianlong4526888/article/details/27695173 版权声明:本文为博主原创文章,未经博主允许不得转载. 说明: 该流程图 ...