网页制作asp.net用vb写登录语句(强调VB)
这是我的登录页面的全部代码:<%@PageLanguage="VB"ContentType="text/html"ResponseEncoding="gb2312"%><...
这是我的登录页面的全部代码:
<%@ Page Language="VB" ContentType="text/html" ResponseEncoding="gb2312" %>
<!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">
<%@ import namespace="system.data" %>
<%@ import namespace="system.data.sqlclient" %>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>登录</title>
</head>
<script language="vb" runat="server">
sub Button1_click(sender as object,e as eventargs)
dim xi as string
xi=username.text
if xi<>"" then
dim str="select * from 登录 where 用户名='" & xi & "' and 密码='" & password.text & "'"
response.redirect("index.aspx")
else
response.redirect("login.aspx")
end if
end sub
sub page_load(sender as object,e as eventargs)
Dim MyConnection As SqlConnection=New SqlConnection("server=127.0.0.1;user id=sa;password=;database=asp")
MyConnection.Open()
end sub
</script>
<body>
<body>
<form runat="server" method="post">
<p align="center">欢迎您登录</p>
<table width="426" border="1" align="center">
<tr>
<td width="99">用户名:</td>
<td width="311"><asp:TextBox ID="username" MaxLength="16" TextMode="SingleLine" runat="server" />
<asp:RequiredFieldValidator ControlToValidate="username" Display="Dynamic" ErrorMessage="请输入用户名!" ID="aa" runat="server" /></td>
</tr>
<tr>
<td>密码:</td>
<td><asp:TextBox ID="password" MaxLength="30" TextMode="Password" runat="server" />
<asp:RequiredFieldValidator ControlToValidate="password" Display="Dynamic" ErrorMessage="请输入密码!" ID="bb" runat="server" /></td>
</tr>
<tr>
<td colspan="2" align="center"><asp:Button ID="Button1" runat="server" Text="登录" OnClick="Button1_click" />
<asp:Button ID="Button2" Text="重置" runat="server" /></td>
</tr>
</table>
<p align="center"> </p>
</form>
</body>
</html>
数据库应该是连上了~!
可以SQL语句那里应该还有问题
当我执行时
只要登录和密码的文本框不为空
并且不管有没有对应上数据库里边的数据
都转到index.aspx这个页面~!
我现在是要实现让它必须对应上数据库里边的数据才可以进入index.aspx界面
否则
回到login.aspx登录页面~!
我应该如何写那些语句?
强调一下`!
一定要用VB来写~!(不要用其它的,我不懂~只要VB~)
逐鹿传说
我按照您给的方法
可是还是转不到index.aspx界面 展开
<%@ Page Language="VB" ContentType="text/html" ResponseEncoding="gb2312" %>
<!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">
<%@ import namespace="system.data" %>
<%@ import namespace="system.data.sqlclient" %>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>登录</title>
</head>
<script language="vb" runat="server">
sub Button1_click(sender as object,e as eventargs)
dim xi as string
xi=username.text
if xi<>"" then
dim str="select * from 登录 where 用户名='" & xi & "' and 密码='" & password.text & "'"
response.redirect("index.aspx")
else
response.redirect("login.aspx")
end if
end sub
sub page_load(sender as object,e as eventargs)
Dim MyConnection As SqlConnection=New SqlConnection("server=127.0.0.1;user id=sa;password=;database=asp")
MyConnection.Open()
end sub
</script>
<body>
<body>
<form runat="server" method="post">
<p align="center">欢迎您登录</p>
<table width="426" border="1" align="center">
<tr>
<td width="99">用户名:</td>
<td width="311"><asp:TextBox ID="username" MaxLength="16" TextMode="SingleLine" runat="server" />
<asp:RequiredFieldValidator ControlToValidate="username" Display="Dynamic" ErrorMessage="请输入用户名!" ID="aa" runat="server" /></td>
</tr>
<tr>
<td>密码:</td>
<td><asp:TextBox ID="password" MaxLength="30" TextMode="Password" runat="server" />
<asp:RequiredFieldValidator ControlToValidate="password" Display="Dynamic" ErrorMessage="请输入密码!" ID="bb" runat="server" /></td>
</tr>
<tr>
<td colspan="2" align="center"><asp:Button ID="Button1" runat="server" Text="登录" OnClick="Button1_click" />
<asp:Button ID="Button2" Text="重置" runat="server" /></td>
</tr>
</table>
<p align="center"> </p>
</form>
</body>
</html>
数据库应该是连上了~!
可以SQL语句那里应该还有问题
当我执行时
只要登录和密码的文本框不为空
并且不管有没有对应上数据库里边的数据
都转到index.aspx这个页面~!
我现在是要实现让它必须对应上数据库里边的数据才可以进入index.aspx界面
否则
回到login.aspx登录页面~!
我应该如何写那些语句?
强调一下`!
一定要用VB来写~!(不要用其它的,我不懂~只要VB~)
逐鹿传说
我按照您给的方法
可是还是转不到index.aspx界面 展开
1个回答
展开全部
sub Button1_click(sender as object,e as eventargs)
if xi<>"" then
response.redirect("login.aspx")
end if
Dim MyConnection As SqlConnection
Dim cmd As SqlCommand
Dim r As Integer
MyConnection = New SqlConnection("server=127.0.0.1;user id=sa;password=;database=asp")
Try
MyConnection.Open()
dim str="select * from 登录 where 用户名='" & xi & "' and 密码='" & password.text & "'"
cmd = New SqlCommand(str)
cmd.Connection = MyConnection
r = cmd.ExecuteNonQuery
If r = 1 Then
response.redirect("index.aspx")
End If
Catch ex As Exception
finally
myconnection.close
End Try
end sub
sub page_load(sender as object,e as eventargs)
end sub
if xi<>"" then
response.redirect("login.aspx")
end if
Dim MyConnection As SqlConnection
Dim cmd As SqlCommand
Dim r As Integer
MyConnection = New SqlConnection("server=127.0.0.1;user id=sa;password=;database=asp")
Try
MyConnection.Open()
dim str="select * from 登录 where 用户名='" & xi & "' and 密码='" & password.text & "'"
cmd = New SqlCommand(str)
cmd.Connection = MyConnection
r = cmd.ExecuteNonQuery
If r = 1 Then
response.redirect("index.aspx")
End If
Catch ex As Exception
finally
myconnection.close
End Try
end sub
sub page_load(sender as object,e as eventargs)
end sub
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询