网页制作asp.net用vb写登录语句(强调VB)
sub Button1_click(sender as object,e as eventargs)
成都创新互联公司基于10余年网站建设行业经验,一直致力于为中小型企业提供信息化解决方案,成都创新互联公司做到开放、开源,让企业所有核心数据掌握到企业手里,打破行业乱象,让企业被网络公司掌控的局面不再发生;美工设计部,产品/程序研发部,营销策划部,售后客服部。一切服务为企业量身定制,专注为您!
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
vb语言asp.net登陆代码 急
人家要vb的。。。一楼的不地道。
Partial Class Login
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
btnLogin.Enabled = True
lblMsg.Text = ""
If Session("loginName") "" Then
btnLogin.Enabled = False
lblMsg.Text = "Please Logout first."
End If
txtName.Focus()
End Sub
Protected Sub btnlogin_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnLogin.Click
Dim objDBUser As New cDBUser
If objDBUser.checkLoginName(txtName.Text) = 1 Then
Dim accessLv As Integer = objDBUser.checkPassword(txtName.Text, txtPwd.Text)
If accessLv = -1 Then
lblMsg.Text = "Wrong Password. Please try again."
txtPwd.Focus()
ElseIf accessLv = 0 Then
lblMsg.Text = "Your account is locked. Contact with site admin."
Else
lblMsg.Text = "Login successfully."
Dim loginName As String = txtName.Text
Session.Add("loginName", loginName)
Session.Add("userName", objDBUser.getUserName(loginName))
Response.Redirect("Index.aspx")
End If
Else
lblMsg.Text = "Wrong Login Name."
txtName.Focus()
End If
End Sub
Protected Sub btnLogout_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnLogout.Click
Session.Clear()
End Sub
End Class
这个是code behind file
另外需要在app code 里面放一个叫dbUser和Cuser的class
Imports Microsoft.VisualBasic
Imports System.Data.SqlClient
Imports System.Data
Public Class cDBUser
Private conn As New SqlConnection
Private connstr As String = System.Configuration.ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString
Private sqlCmd As New SqlCommand
Public Sub New()
conn.ConnectionString = connstr
sqlCmd.Connection = conn
End Sub
Public Function checkLoginName(ByVal loginName As String) As Integer
Try
conn.Open()
sqlCmd.CommandText = "SELECT COUNT(password) FROM tblUser where LoginName = '" loginName "'"
Return sqlCmd.ExecuteScalar
Catch ex As Exception
MsgBox(ex.Message)
Return 0
Finally
conn.Close()
End Try
End Function
Public Function checkPassword(ByVal loginName As String, ByVal pwd As String) As Integer
Try
conn.Open()
sqlCmd.CommandText = "SELECT COUNT(*) FROM tblUser WHERE loginName = '" loginName _
"' and password = '" pwd "'"
Dim passwordOK As Integer = sqlCmd.ExecuteScalar
If passwordOK = 1 Then
sqlCmd.CommandText = "SELECT accesslevel FROM tblUser WHERE loginName = '" loginName _
"' and password = '" pwd "' and status = 1"
Return CInt(sqlCmd.ExecuteScalar)
Else
Return -1
End If
Catch ex As Exception
MsgBox(ex.Message)
Return 0
Finally
conn.Close()
End Try
End Function
Public Function getOldPwd(ByVal loginName As String) As String
Try
conn.Open()
sqlCmd.CommandText = "SELECT Password FROM tblUser WHERE LoginName = '" loginName "'"
Return sqlCmd.ExecuteScalar
Catch ex As Exception
MsgBox(ex.Message)
Return Nothing
Finally
conn.Close()
End Try
End Function
Public Function getUserName(ByVal loginName As String) As String
Try
conn.Open()
sqlCmd.CommandText = "SELECT UserName FROM tblUser WHERE LoginName = '" loginName "'"
Return sqlCmd.ExecuteScalar
Catch ex As Exception
MsgBox(ex.Message)
Return Nothing
Finally
conn.Close()
End Try
End Function
Public Function getAllUsers() As DataView
Try
conn.Open()
Dim sqlAdpt As New SqlDataAdapter("SELECT userID,LoginName,UserName,Email,AccessLevel,Status FROM tblUser", connstr)
Dim dt As New DataTable
sqlAdpt.Fill(dt)
Return dt.DefaultView
Catch ex As Exception
MsgBox(ex.Message)
Return Nothing
Finally
conn.Close()
End Try
End Function
Public Function getUserDetails(ByVal loginName As String) As cUser
Try
conn.Open()
Dim sqlAdpt As New SqlDataAdapter("SELECT * from tblUser where loginName = '" loginName "'", connstr)
Dim dt As New DataTable
sqlAdpt.Fill(dt)
Dim dr As DataRow = dt.Rows(0)
Dim objUser As New cUser
objUser.userId = dr.Item("UserId")
objUser.loginName = dr.Item("LoginName")
objUser.password = dr.Item("Password")
objUser.userName = dr.Item("UserName")
objUser.Email = dr.Item("Email")
objUser.accessLevel = dr.Item("AccessLevel")
objUser.status = dr.Item("Status")
Return objUser
Catch ex As Exception
MsgBox(ex.Message)
Return Nothing
Finally
conn.Close()
End Try
End Function
Public Function changeUserStatus(ByVal userId As Integer) As Integer
Try
conn.Open()
sqlCmd.CommandText = "UPDATE tblUser SET status = (1 - status) WHERE userId = " userId
Return CInt(sqlCmd.ExecuteScalar)
Catch ex As Exception
MsgBox(ex.Message)
Return 0
Finally
conn.Close()
End Try
End Function
Public Function changeEmail(ByVal loginName As String, ByVal newEmail As String) As Integer
Try
conn.Open()
sqlCmd.CommandText = "UPDATE tblUser SET Email = '" newEmail "' WHERE LoginName = '" loginName "'"
Return sqlCmd.ExecuteNonQuery
Catch ex As Exception
MsgBox(ex.Message)
Return 0
Finally
conn.Close()
End Try
End Function
Public Function changePwd(ByVal loginName As String, ByVal newPwd As String) As Integer
Try
conn.Open()
sqlCmd.CommandText = "UPDATE tblUser SET password = '" newPwd "' WHERE loginName = '" loginName "'"
Return sqlCmd.ExecuteNonQuery
Catch ex As Exception
MsgBox(ex.Message)
Return 0
Finally
conn.Close()
End Try
End Function
Public Function addUser(ByVal objUser As cUser) As Integer
Try
conn.Open()
sqlCmd.CommandText = "INSERT INTO tblUser (userName,loginName,password,email,accessLevel,status) VALUES('" _
Trim(objUser.userName) "','" Trim(objUser.loginName) "','" objUser.password "','" Trim(objUser.Email) "','" _
objUser.accessLevel "',1)"
If sqlCmd.ExecuteNonQuery() = 1 Then
sendEmail()
Return 1
End If
Catch ex As Exception
MsgBox(ex.Message)
Return 0
Finally
conn.Close()
End Try
End Function
Public Function retrievePwd(ByVal loginName As String) As Integer
Try
conn.Open()
sqlCmd.CommandText = "SELECT password from tblUser where loginName = '" loginName "'"
Dim pwd As String = sqlCmd.ExecuteScalar
Dim email As String = getEmail(loginName)
If email "" And pwd "" Then
sendEmail()
Return 1
Else
Return 0
End If
Catch ex As Exception
MsgBox(ex.Message)
Return 0
Finally
conn.Close()
End Try
End Function
Public Function getEmail(ByVal loginName As String) As String
conn.Close()
Try
conn.Open()
sqlCmd.CommandText = "SELECT Email from tblUser where loginName = '" loginName "'"
Dim email As String = sqlCmd.ExecuteScalar
Return email
Catch ex As Exception
MsgBox(ex.Message)
Return ""
Finally
conn.Close()
End Try
End Function
Private Sub sendEmail()
'some code here to send email
End Sub
End Class
Imports Microsoft.VisualBasic
Public Class cUser
Private intUserId As Integer
Private strUserName As String
Private strLoginName As String
Private strPassword As String
Private strEmail As String
Private shortAccessLevel As Short
Private byteStatus As Byte
Public Sub New()
End Sub
Public Property userId() As Integer
Get
Return intUserId
End Get
Set(ByVal value As Integer)
intUserId = value
End Set
End Property
Public Property userName() As String
Get
Return strUserName
End Get
Set(ByVal value As String)
strUserName = value
End Set
End Property
Public Property loginName() As String
Get
Return strLoginName
End Get
Set(ByVal value As String)
strLoginName = value
End Set
End Property
Public Property password() As String
Get
Return strPassword
End Get
Set(ByVal value As String)
strPassword = value
End Set
End Property
Public Property Email() As String
Get
Return strEmail
End Get
Set(ByVal value As String)
strEmail = value
End Set
End Property
Public Property accessLevel() As String
Get
Return shortAccessLevel
End Get
Set(ByVal value As String)
shortAccessLevel = value
End Set
End Property
Public Property status() As Byte
Get
Return byteStatus
End Get
Set(ByVal value As Byte)
byteStatus = value
End Set
End Property
End Class
vb.net 连接SQL数据库登录代码
问题应该出在你的查询语句的结果没有值,你用你的查询语句到SQL中是否有返回值?记得加上你的条件,另外,你语句里这一句是多余的.Dim s As Object = sComm.ExecuteScalar 以下语句测试正常 Dim myCn As New SqlClient.SqlConnection Try myCn.ConnectionString = sConnString myCn.Open() Dim mySQL As String = "SELECT * FROM ygzl" Dim sComm As New SqlClient.SqlCommand(mySQL, myCn) If sComm.ExecuteScalar Then Dim User_MainForm As New Form1 User_MainForm.Show() Else MsgBox("用户名或密码不正确,请重试!") End If Catch ex As Exception MsgBox(ex.Message) Finally myCn.Close() '关闭连接 End Try
高手帮我忙啊! VB.NET编的登入代码出现问题
把针对数据库的地方做的声明都new了试试
而且你的SQL文好像有问题。'用户名'列看看是不是不存在或是查询时出现了多个。
vb.net 用户登录
哈哈简单哪
第一步:登陆网页代码
第二步:登陆以后判断是否登陆成功
有两种方法:1.获取网页代码,判断网页字符有无”登陆成功”字样
源代码:
2.就是判断网页是否跳转到了某一页
源代码:
两种方法结合起来用,可以判断网页是否无法连接
网站栏目:.net登录代码VB,net账号
文章来源:http://lswzjz.com/article/hssioh.html