用vb做一个用户登陆界面,用户名和密码都保存在access 数据库中
1个回答
展开全部
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim conn As New SqlConnection
Dim str_conn As String
str_conn = "data source=(local);database=数据库名称;integrated security=sspi"
conn.ConnectionString = str_conn
Dim cmd As New SqlCommand
Dim sql As String = "select count(*) from 表名 where 用户名='" & Trim(Me.TextBox1.Text) & "'and 密码='" & Trim(Me.TextBox2.Text) & "'"
cmd.CommandText = sql
cmd.Connection = conn
Try
conn.Open()
Dim i As Integer
i = 0
i = cmd.ExecuteScalar
If i = 1 Then
Me.Response.Redirect("default2.aspx")
Else
Me.Label1.Text = ("用户或密码错误")
End If
Catch ex As Exception
End Try
conn.Close()
End Sub
End Class
Dim conn As New SqlConnection
Dim str_conn As String
str_conn = "data source=(local);database=数据库名称;integrated security=sspi"
conn.ConnectionString = str_conn
Dim cmd As New SqlCommand
Dim sql As String = "select count(*) from 表名 where 用户名='" & Trim(Me.TextBox1.Text) & "'and 密码='" & Trim(Me.TextBox2.Text) & "'"
cmd.CommandText = sql
cmd.Connection = conn
Try
conn.Open()
Dim i As Integer
i = 0
i = cmd.ExecuteScalar
If i = 1 Then
Me.Response.Redirect("default2.aspx")
Else
Me.Label1.Text = ("用户或密码错误")
End If
Catch ex As Exception
End Try
conn.Close()
End Sub
End Class
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询