我也做了一个登录界面!数据库是用ACCESS做的一个userID表!
代码如下:
Imports System.Data
Imports System.Data.oledb
Public Class Frmlogin
Inherits System.Windows.Forms.Form
Public adocmd As oledbDataAdapter
Public ds As DataSet = New DataSet
Public mytable As Data.DataTable
Public myrow As Data.DataRow
Public rownumber As Integer
Public searchsql As String
Public cmd As oledbCommandBuilder
Private Sub BtnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnOK.Click
Try
Me.Text = "正在验证...."
Me.Cursor = System.Windows.Forms.Cursors.WaitCursor
Dim tablename As String
tablename = "userID"
searchsql = "select 用户名,密码 from userID where(用户名='" & Txtusername.Text & " ')"
Executesql(searchsql, tablename)
If myrow.Item(1) = txtuserpassword.text Then
Dim newfrmmain As New Frmmain
newfrmmain.Show()
Me.Hide()
Else
MsgBox("密码错误")
Txtuserpassword.Text = ""
Me.Text = ""
Me.Cursor = System.Windows.Forms.Cursors.Arrow
Txtuserpassword.Focus()
End If
Catch ex As Exception
MsgBox("用户名不存在!", MsgBoxStyle.OKOnly, "提示")
Txtusername.Text = ""
Txtuserpassword.Text = ""
Me.Text = ""
Me.Cursor = System.Windows.Forms.Cursors.Arrow
End Try
End Sub
Private Sub BtnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnCancel.Click
Me.Dispose()
End Sub
Public Function Executesql(ByVal sql As String, ByVal table As String)
adocmd = New OleDbDataAdapter(sql, "provider=microsoft .jet.oledb.4.0;data source=c:\student")
adocmd.Fill(ds, table)
mytable = ds.Tables.Item(0)
rownumber = 0
myrow = mytable.Rows.Item(rownumber)
End Function
End Class
可以运行,但是无论我输入什么都是提示“用户名不存在”,大家帮忙看看哪出错了。