asp.net 实现登陆实例
登陆页面的代码
<form id="form1" action="login.aspx" method="post">
<div>
<table style="width:100%;">
<tr>
<td class="style3">
</td>
<td class="style4">
<input id="Text1" name="tstUserName" type="text" /></td>
<td class="style5">
</td>
</tr>
<tr>
<td class="style6">
</td>
<td class="style7">
<input id="Text2" name="txtUserPwd" type="text" /></td>
<td class="style8">
</td>
</tr>
<tr>
<td class="style9">
</td>
<td class="style10">
<input id="btnlogin" type="submit" value="提交" /></td>
<td class="style11">
</td>
</tr>
</table>
处理页面的代码 :
string userName = Request.Form["tstUserName"].ToString();
string userPwd = Request.Form["txtUserPwd"].ToString();
Response.Write("你的登录名为" + userName);
SqlConnection con = new SqlConnection("server=.;database=login;uid=sa;pwd=sa;");
con.Open();
SqlCommand cmd = new SqlCommand("select count(*) from login where userName='"+userName+"'and userPwd='"+userPwd+"'",con);
int count =Convert.ToInt32(cmd.ExecuteScalar());
if(count>0)
{
Response.Write("登陆成功");
}
else
{
Response.Write("登陆失败");
}
入门asp.net 代码分析,vagabond
附加 数据脚本文件
create database login
use login
create table login (
userName varchar(20) not null primary key,
userPwd varchar(20) not null,
userIdentity varchar(20) not null,
)
insert into login values ('tjc','123','管理员')
select * from login