asp.net (vb)编写登陆页面(100分)
我想请问用asp.net(vb)编写登陆页面就是先在sqlserver中先建一张表,然后调用里面的用户名,密码,或者说可以先注册,写入表里,然后在调用登陆登陆后符合表里的...
我想请问用asp.net (vb)编写登陆页面
就是先在sql server 中先建一张表,然后调用里面的用户名,密码,或者说可以先注册,写入表里,然后在调用 登陆 登陆后符合表里的内容的转到页面一,如果错误的转到页面二,可以把代码详细的写出来吗,或者给个例子,有实例的最好,谢谢了
谢谢一楼的呀,我考试要用到,如果问题解决了,在加50分给你,谢了,呵呵 展开
就是先在sql server 中先建一张表,然后调用里面的用户名,密码,或者说可以先注册,写入表里,然后在调用 登陆 登陆后符合表里的内容的转到页面一,如果错误的转到页面二,可以把代码详细的写出来吗,或者给个例子,有实例的最好,谢谢了
谢谢一楼的呀,我考试要用到,如果问题解决了,在加50分给你,谢了,呵呵 展开
3个回答
展开全部
system.data.sqlclient,而access则是引用的system.data.oledb
sub qd1(sender as object,e as eventargs)
dim user,pas as string
user = xm.text
pas = mm.text
dim myconn as string
myconn = "provider=microsoft.jet.oledb.4.0;" & "data source="& server.mappath("data/fang.mdb")
dim xm1,zw,qx as string
'检查用户名是否为空
if xm.text<>"" then
try
dim mysql as string
mysql="select * from 管理 where 用户名='"& user &"' and 密码='"& mm &"'"
dim mycmd as oledbdataadapter = new oledbdataadapter(mysql,myconn)
dim ds as dataset = new dataset()
mycmd.fill(ds,"管理")
dim mytable1 as datatable
mytable1=ds.tables("管理")
if user=mytable1.rows(0).item(1) and pas=mytable1.rows(0).item(3) then
xm.text=""
else
message.text="请重新输入!"
end if
catch ex as exception
message.text="用户名或密码有问题,请确认后重新输入!"
end try
else
message.text="用户名或密码有问题,请确认后重新输入!"
end if
end sub
下面是注册用的,可以同时检查是否有重名。
dim myconn as oledbconnection
dim mycmd,mycmd1,mycmd2,mycmd3 as oledbcommand
dim strcon as string
dim strsql,strsql1,strsql2 as string
strcon ="provider=microsoft.jet.oledb.4.0;"&"data source="&server.mappath("data/fang.mdb")
myconn = new oledbconnection(strcon)
myconn.open()
strsql = "select * from 管理 where 管理.用户名='"& m_1 &"'"
mycmd = new oledbcommand(strsql,myconn)
dim reader as oledbdatareader
reader = mycmd.executereader()
if reader.read() then '若存在
message.text="您输入的用户名已存在,请重新输入!"
reader.close()
myconn.close()
else '不存在,写入数据库
reader.close()
if m_4="管理员" then
strsql1="insert into 管理() values()"
mycmd1 = new oledbcommand(strsql1,myconn)
mycmd1.executenonquery
myconn.close()
message.text="您已成功注册!"
else
strsql2="insert into 管理() values()"
mycmd2 = new oledbcommand(strsql2,myconn)
mycmd2.executenonquery
myconn.close()
message.text="您已成功注册!"
end if
end if
else
message.text = "请检查页面中是否有错误!"
end if
end if
end sub
sub qd1(sender as object,e as eventargs)
dim user,pas as string
user = xm.text
pas = mm.text
dim myconn as string
myconn = "provider=microsoft.jet.oledb.4.0;" & "data source="& server.mappath("data/fang.mdb")
dim xm1,zw,qx as string
'检查用户名是否为空
if xm.text<>"" then
try
dim mysql as string
mysql="select * from 管理 where 用户名='"& user &"' and 密码='"& mm &"'"
dim mycmd as oledbdataadapter = new oledbdataadapter(mysql,myconn)
dim ds as dataset = new dataset()
mycmd.fill(ds,"管理")
dim mytable1 as datatable
mytable1=ds.tables("管理")
if user=mytable1.rows(0).item(1) and pas=mytable1.rows(0).item(3) then
xm.text=""
else
message.text="请重新输入!"
end if
catch ex as exception
message.text="用户名或密码有问题,请确认后重新输入!"
end try
else
message.text="用户名或密码有问题,请确认后重新输入!"
end if
end sub
下面是注册用的,可以同时检查是否有重名。
dim myconn as oledbconnection
dim mycmd,mycmd1,mycmd2,mycmd3 as oledbcommand
dim strcon as string
dim strsql,strsql1,strsql2 as string
strcon ="provider=microsoft.jet.oledb.4.0;"&"data source="&server.mappath("data/fang.mdb")
myconn = new oledbconnection(strcon)
myconn.open()
strsql = "select * from 管理 where 管理.用户名='"& m_1 &"'"
mycmd = new oledbcommand(strsql,myconn)
dim reader as oledbdatareader
reader = mycmd.executereader()
if reader.read() then '若存在
message.text="您输入的用户名已存在,请重新输入!"
reader.close()
myconn.close()
else '不存在,写入数据库
reader.close()
if m_4="管理员" then
strsql1="insert into 管理() values()"
mycmd1 = new oledbcommand(strsql1,myconn)
mycmd1.executenonquery
myconn.close()
message.text="您已成功注册!"
else
strsql2="insert into 管理() values()"
mycmd2 = new oledbcommand(strsql2,myconn)
mycmd2.executenonquery
myconn.close()
message.text="您已成功注册!"
end if
end if
else
message.text = "请检查页面中是否有错误!"
end if
end if
end sub
展开全部
下面是一个响应登录事件。
用户名在textbox xm中,密码在textbox mm中。
先是将用户名与密码的值取过来。然后在和数据库中已有的用户名和密码进行比较,如果都正确就表示可以登录。否则就不可以。不过我的这段中使用的是ACCESS数据库,其实基本原理和用SQL是一样的,只不过要引用system.data.sqlclient,而access则是引用的system.data.oledb
sub qd1(sender as object,e as eventargs)
dim user,pas as string
user = xm.text
pas = mm.text
dim myconn as string
myconn = "provider=microsoft.jet.oledb.4.0;" & "data source="& server.mappath("data/fang.mdb")
dim xm1,zw,qx as string
'检查用户名是否为空
if xm.text<>"" then
try
dim mysql as string
mysql="select * from 管理 where 用户名='"& user &"' and 密码='"& mm &"'"
dim mycmd as oledbdataadapter = new oledbdataadapter(mysql,myconn)
dim ds as dataset = new dataset()
mycmd.fill(ds,"管理")
dim mytable1 as datatable
mytable1=ds.tables("管理")
if user=mytable1.rows(0).item(1) and pas=mytable1.rows(0).item(3) then
xm.text=""
else
message.text="请重新输入!"
end if
catch ex as exception
message.text="用户名或密码有问题,请确认后重新输入!"
end try
else
message.text="用户名或密码有问题,请确认后重新输入!"
end if
end sub
下面是注册用的,可以同时检查是否有重名。
dim myconn as oledbconnection
dim mycmd,mycmd1,mycmd2,mycmd3 as oledbcommand
dim strcon as string
dim strsql,strsql1,strsql2 as string
strcon ="provider=microsoft.jet.oledb.4.0;"&"data source="&server.mappath("data/fang.mdb")
myconn = new oledbconnection(strcon)
myconn.open()
strsql = "select * from 管理 where 管理.用户名='"& m_1 &"'"
mycmd = new oledbcommand(strsql,myconn)
dim reader as oledbdatareader
reader = mycmd.executereader()
if reader.read() then '若存在
message.text="您输入的用户名已存在,请重新输入!"
reader.close()
myconn.close()
else '不存在,写入数据库
reader.close()
if m_4="管理员" then
strsql1="insert into 管理() values()"
mycmd1 = new oledbcommand(strsql1,myconn)
mycmd1.executenonquery
myconn.close()
message.text="您已成功注册!"
else
strsql2="insert into 管理() values()"
mycmd2 = new oledbcommand(strsql2,myconn)
mycmd2.executenonquery
myconn.close()
message.text="您已成功注册!"
end if
end if
else
message.text = "请检查页面中是否有错误!"
end if
end if
end sub
用户名在textbox xm中,密码在textbox mm中。
先是将用户名与密码的值取过来。然后在和数据库中已有的用户名和密码进行比较,如果都正确就表示可以登录。否则就不可以。不过我的这段中使用的是ACCESS数据库,其实基本原理和用SQL是一样的,只不过要引用system.data.sqlclient,而access则是引用的system.data.oledb
sub qd1(sender as object,e as eventargs)
dim user,pas as string
user = xm.text
pas = mm.text
dim myconn as string
myconn = "provider=microsoft.jet.oledb.4.0;" & "data source="& server.mappath("data/fang.mdb")
dim xm1,zw,qx as string
'检查用户名是否为空
if xm.text<>"" then
try
dim mysql as string
mysql="select * from 管理 where 用户名='"& user &"' and 密码='"& mm &"'"
dim mycmd as oledbdataadapter = new oledbdataadapter(mysql,myconn)
dim ds as dataset = new dataset()
mycmd.fill(ds,"管理")
dim mytable1 as datatable
mytable1=ds.tables("管理")
if user=mytable1.rows(0).item(1) and pas=mytable1.rows(0).item(3) then
xm.text=""
else
message.text="请重新输入!"
end if
catch ex as exception
message.text="用户名或密码有问题,请确认后重新输入!"
end try
else
message.text="用户名或密码有问题,请确认后重新输入!"
end if
end sub
下面是注册用的,可以同时检查是否有重名。
dim myconn as oledbconnection
dim mycmd,mycmd1,mycmd2,mycmd3 as oledbcommand
dim strcon as string
dim strsql,strsql1,strsql2 as string
strcon ="provider=microsoft.jet.oledb.4.0;"&"data source="&server.mappath("data/fang.mdb")
myconn = new oledbconnection(strcon)
myconn.open()
strsql = "select * from 管理 where 管理.用户名='"& m_1 &"'"
mycmd = new oledbcommand(strsql,myconn)
dim reader as oledbdatareader
reader = mycmd.executereader()
if reader.read() then '若存在
message.text="您输入的用户名已存在,请重新输入!"
reader.close()
myconn.close()
else '不存在,写入数据库
reader.close()
if m_4="管理员" then
strsql1="insert into 管理() values()"
mycmd1 = new oledbcommand(strsql1,myconn)
mycmd1.executenonquery
myconn.close()
message.text="您已成功注册!"
else
strsql2="insert into 管理() values()"
mycmd2 = new oledbcommand(strsql2,myconn)
mycmd2.executenonquery
myconn.close()
message.text="您已成功注册!"
end if
end if
else
message.text = "请检查页面中是否有错误!"
end if
end if
end sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
谢就不用了.呵呵.共同提高到是真的.我下周.net考试,我用asp.net(C#)做了一个图书书店系统.应该还行吧,你要的话我发给你
我QQ511290869,方便的话给我也改一下.呵呵.共同提高
数据库的创建
create database Login
go
use Login
drop table Loginname
create table Loginname
(
ID int primary key ,
name nvarchar(12) NOT NULL ,
password nvarchar(20) NOT NULL
)
insert into Loginname values (1,'admin','admin')
select * from Loginname where Name ='admin' and password='admin'
我用.net做的
default.aspx
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<!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>
<asp:Label ID="lbUserName" runat="server" Text="用户名"></asp:Label>
<asp:TextBox ID="tbUserName" runat="server"></asp:TextBox>
<br />
<asp:Label ID="lbPassword" runat="server" Text="密码:"></asp:Label>
<asp:TextBox ID="tbPassword" runat="server" TextMode="Password"></asp:TextBox>
<br />
<asp:Button ID="sender" runat="server" Text="提交" /></div>
</form>
</body>
</html>
DEfault.aspx.vb
Imports System.Data.SqlClient
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
Protected Sub sender_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles sender.Click
Dim strsql As String
strsql = "select * from Loginname where Name =" + "'" + Me.tbUserName.Text.ToString() + "'" + " and password = " + "'" + Me.tbPassword.Text.ToString() + "'"
'strsql = "select * from Users where Name ='admin'"
Dim conn As SqlConnection
conn = New SqlConnection("Data Source=.;Initial Catalog=Login;Integrated Security=True")
conn.Open()
Dim com As SqlCommand
com = New SqlCommand(strsql, conn)
If (Convert.ToInt32(com.ExecuteScalar()) > 0) Then
Response.Redirect("LoginIN.aspx")
Else
Response.Redirect("err.aspx")
End If
conn.Close()
End Sub
End Class
我QQ511290869,方便的话给我也改一下.呵呵.共同提高
数据库的创建
create database Login
go
use Login
drop table Loginname
create table Loginname
(
ID int primary key ,
name nvarchar(12) NOT NULL ,
password nvarchar(20) NOT NULL
)
insert into Loginname values (1,'admin','admin')
select * from Loginname where Name ='admin' and password='admin'
我用.net做的
default.aspx
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<!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>
<asp:Label ID="lbUserName" runat="server" Text="用户名"></asp:Label>
<asp:TextBox ID="tbUserName" runat="server"></asp:TextBox>
<br />
<asp:Label ID="lbPassword" runat="server" Text="密码:"></asp:Label>
<asp:TextBox ID="tbPassword" runat="server" TextMode="Password"></asp:TextBox>
<br />
<asp:Button ID="sender" runat="server" Text="提交" /></div>
</form>
</body>
</html>
DEfault.aspx.vb
Imports System.Data.SqlClient
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
Protected Sub sender_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles sender.Click
Dim strsql As String
strsql = "select * from Loginname where Name =" + "'" + Me.tbUserName.Text.ToString() + "'" + " and password = " + "'" + Me.tbPassword.Text.ToString() + "'"
'strsql = "select * from Users where Name ='admin'"
Dim conn As SqlConnection
conn = New SqlConnection("Data Source=.;Initial Catalog=Login;Integrated Security=True")
conn.Open()
Dim com As SqlCommand
com = New SqlCommand(strsql, conn)
If (Convert.ToInt32(com.ExecuteScalar()) > 0) Then
Response.Redirect("LoginIN.aspx")
Else
Response.Redirect("err.aspx")
End If
conn.Close()
End Sub
End Class
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询