如何用VB2005做一个登录页面,若用户名和密码均正确,则进入系统,否则提示输入的信息有误...........请指教.......
Imports System.Data.SqlClient
Public Class FormLogin
'全局变量
Public Const connstr As String = "Data Source=.\SQLEXPRESS;AttachDbFilename=G:\PROGRAM\COMMODITY SYSTEM\DATABASE\COMMODITY_DATA.MDF;Integrated Security=True;Connect Timeout=30;User Instance=True"
'Public Const connstr As String = "integrated security=sspi;initial catalog=commodity;data source=localhost"
Protected Const getallusers As String = "select name,password from 管理员信息 order by name"
Private _users As DataTable
Public user As String
Public password As String
Dim comm As New SqlCommand
Dim ds As New DataSet
Dim da As New SqlDataAdapter
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim frm2 As New FormMenu
Dim conn As New SqlConnection(connstr)
user = TBName.Text
password = TBPassword.Text
Dim str As String
str = "select * from 管理员信息 where name='" & user & "' and password='" & password & "' "
comm.Connection = conn
comm.CommandType = CommandType.Text
comm.CommandText = str
da.SelectCommand = comm
Try
conn.Open()
da.Fill(ds)
If ds.Tables(0).Rows.Count <> 0 Then
frm2.Show()
Me.Close()
Else
MessageBox.Show("密码或用户名错误,请重新输入", "提示信息")
TBName.Text = ""
TBPassword.Text = ""
TBName.Focus()
End If
Catch ex As Exception
MessageBox.Show("登陆失败", "ERROR")
End Try
End Sub
End Class