<%@ Page Language="C#" AutoEventWireup="true" CodeFile="UserLogin.aspx.cs" Inherits="UserLogin" %> 

<!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>
<div align="center">
<h1>用户登录页面</h1>
<form id="form1" runat="server">
<p> <asp:Label ID="lbusername" runat="server">用户名:</asp:Label>
<asp:TextBox ID="tbusername" runat="server"></asp:TextBox>
</p> <p> <asp:Label ID="lbpsw" runat="server">密 码:</asp:Label>
<asp:TextBox ID="tbpsw" runat="server" TextMode="Password"></asp:TextBox>
</p>
<p><asp:Button ID="btnLogin" runat="server" Text="登录" onclick="btnLogin_Click" />
<asp:Button ID="btnCancel" runat="server" Text="取消" onclick="btnCancel_Click" />
</p>
</form>
</div>
</body>
</html>
/// <summary>
/// 用户登录
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnLogin_Click(object sender, EventArgs e)
{
if (tbusername.Text == "")
{
Response.Write(@"<script>alert('用户名不能为空!');</script>");
}
if (tbpsw.Text == "")
{
Response.Write(@"<script>alert('密码不能为空!');</script>");
}
string username = tbusername.Text;
string password = tbpsw.Text;
string sql = "select * from T_user where username=@username and password=@password";
SqlParameter[] parameters = { new SqlParameter("@username",username), new SqlParameter("@password", password) };
using (SqlConnection conn = new SqlConnection(connstr))
{
conn.Open();
using (SqlCommand cmd = conn.CreateCommand())
{
cmd.CommandText = sql;
cmd.Parameters.AddRange(parameters);
DataSet ds = new DataSet();
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
adapter.Fill(ds);
DataTable table = ds.Tables[0];
if(table != null)
Response.Write(@"<script>alert('登录成功!');</script>");
else
Response.Write(@"<script>alert('登录失败!');</script>"); }
} }

  

/// <summary>
/// 用户注册
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void brnRegister_Click(object sender, EventArgs e)
{
string username = tbusername.Text;
string password = tbpsw.Text;
string sql = "Insert into T_user(username, password) values(@username,@password)";
SqlParameter[] parameters = { new SqlParameter("@username", username), new SqlParameter("@password", password) };
using (SqlConnection conn = new SqlConnection(connstr))
{
conn.Open();
using (SqlCommand cmd = conn.CreateCommand())
{
cmd.CommandText = sql;
cmd.Parameters.AddRange(parameters);
cmd.ExecuteNonQuery();
}
} Response.Write(@"<script>alert('注册成功!');</script>");
}

如何利用Visual studio 2010创建一个ASP网站?的更多相关文章

  1. 带你使用Visual Studio 2019创建一个MVC Web应用

    工欲善其事必先利其器,我们既然有Visual Studio2019这样的IDE为什么不用?学.Net Core而不用Visual Studio进行开发可谓是多么另类呀!既然你已经安装了VS2019的话 ...

  2. 使用Visual Studio 2010 创建简单的Silverlight应用程序

    使用Visual Studio 2010 创建简单的Silverlight应用程序 Silverlight是创建动态的引人的RIAs(Rich Internet Application)的新方法.这里 ...

  3. 在 Visual Studio 中创建一个简单的 C# 控制台应用程序

    转载:https://blog.csdn.net/qq_43994242/article/details/87260824 快速入门:使用 Visual Studio 创建第一个 C# 控制台应用 h ...

  4. visual studio 2010 "创建控件时出错"解决办法[转]

    之前我有在博问里面提问(http://space.cnblogs.com/q/16208/),但一直都没答案.我系统都重装了两次了,可还是出现这样的错误,我很郁闷啊.今天我终于找到原因了. 我写了一个 ...

  5. ASP.NET没有魔法——开篇-用VS创建一个ASP.NET Web程序

    为什么写这一系列文章? 本系列文章基于ASP.NET MVC,在ASP.NET Core已经发布2.0版本,微服务漫天的今天为什么还写ASP.NET?. 答:虽然现在已经有ASP.NET Core并且 ...

  6. ASP.NET开发实战——(一)开篇-用VS创建一个ASP.NET Web程序

        本文是本系列文章第一篇,主要通过建立一个默认ASP.NET MVC项目来引出与ASP.NET MVC相关的功能,由于ASP.NET MVC一个简单的模板就具备了数据库操作.身份验证.输入数据校 ...

  7. 在 Visual Studio 2010 中开发和部署 Windows Azure 应用程序

    原文 在 Visual Studio 2010 中开发和部署 Windows Azure 应用程序 在 Visual Studio 2010 中开发和部署 Windows Azure 应用程序 Jim ...

  8. 如何使用visual studio 2017创建C语言项目

    使用visual studio 2017创建一个C语言项目,步骤如下: (1)打开Visual Studio 2017环境后出现欢迎界面,如图1所示. 图1  Visual Studio 2017欢迎 ...

  9. Visual Studio 2010中创建ASP.Net Web Service

    转自:http://blog.csdn.net/xinyaping/article/details/7331375 很多人在论坛里说,在Visual Studio 2010中不能创建“ASP.Net ...

随机推荐

  1. c++ inline关键字的理解

    1. inline是实现修饰符,而非声明修饰符,所以应该用于实现部分的修饰(你也可以放置inline在声明,但是没有必要) 2. 所有中类中定义的函数都默认声明为inline函数,所有我们不用显示地去 ...

  2. innodb更改行格式,系统盘占用急剧升高

    #大表引擎修改后,数据量较myisam引擎表大很多,对存储的行格式修改后,数据量减小. #备库修改时,由于服务器时间较早,系统盘20G,突然收到/磁盘空间占比89%的报警,立即将修改中断,恢复正常 # ...

  3. 4.当接口的请求方式为 application/json的时候时

    1..当接口的请求方式为 application/json的时候时,使用抓包软件(fiddler)获取到这个接口, 其中的Inspectprs-TextView中的内容就是jmeter中Body Da ...

  4. [妙味Ajax]第二课:实例:留言板、瀑布流

    知识点总结 瀑布流原理(固定布局) 总宽度大小固定 每列宽度固定,比如LI,高度自动计算,每列使用float:left来布局 计算最短的一列,将Div插到最短的一列处(li里面包div)(getSho ...

  5. HDU 1008 u Calculate e

    Problem Description A simple mathematical formula for e is where n is allowed to go to infinity. Thi ...

  6. Markdown - Github specific

    这篇文章的内容,必须到github的页面才能全部生效. Github specific Github allows for mistakes There are also Tables in gith ...

  7. [SOJ] 图的广度优先搜索

    Time Limit: 1sec    Memory Limit:256MB Description 读入图的邻接矩阵以及一个顶点的编号(图中顶点的编号为从1开始的连续正整数.顶点在邻接矩阵的行和列上 ...

  8. 朱丽叶—Cuda+OSG

    #include <cuda_runtime.h> #include <osg/Image> ; typedef struct cuComplex { float r; flo ...

  9. Nimbus<一>Storm系列(五)架构分析之Nimbus启动过程

    启动流程图 mk-assignments 功能:对当前集群中所有Topology进行新一轮的任务调度. 实现源码路径: \apache-storm-0.9.4\storm-core\src\clj\b ...

  10. Python库 - import matplotlib.pyplot as plt 报错问题

    为了避免各种问题,请使用最新的2.7.13安装文件   1.先设置好环境变量 在path变量中设置好以下路径: C:\Python27\Scripts C:\Python27    2.大部分报错问题 ...