用VB编写一个登陆界面(急!!)

2024-11-14 23:45:09
推荐回答(5个)
回答1:

vb6加窗体选登录对话框

cmdOK_Click 代码改
dim cnn as new adodb.connection
cnn.open strcnn

dim rs as new adodb.recordset

rs.open "select pwd from tbuser where username = '" & replace(txtUserName.text,"'") & "'",cnn
if rs.eof then
msgbox "无此用户"
rs.close

exit sub
else
if pws = txtPassword.text then
frmMain.show '你要的那个窗体名
rs.close
unload me
endif
endif

回答2:

'引用ADO.NET组件所需命名空间
Imports System.Data
Imports System.Data.OleDb

Module modData
Public connAccessAdress As String = "Data\Book.gdb" '数据库连接地址
Public connAccessKey As String = "PassWord" '数据库连接密码
Public connAccessString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source='" + connAccessAdress + "';Jet OLEDB:Database Password='" + connAccessKey + "'" '联机字符串声明
Public conn As OleDbConnection
Public da As OleDbDataAdapter
Public dr As OleDbDataReader
Public cmd As OleDbCommand
Public ds As DataSet
Public dt As DataTable
Public AccessCommand As String = Nothing

#Region "登陆>加载用户 dataLogin_LoadUser"
Sub dataLogin_LoadUser()
Try
conn = New OleDbConnection(connAccessString)
conn.Open()
AccessCommand = "SELECT dUser.LUser FROM dUser ORDER BY dUser.LID"
da = New OleDbDataAdapter(AccessCommand, conn)

ds = New DataSet
da.Fill(ds, "LoginUserList")

frmLogin.cbbLoginUser.DataSource = ds.Tables("LoginUserList")
frmLogin.cbbLoginUser.DisplayMember = "LUser"

conn.Close()
conn.Dispose()
da.Dispose()
ds.Dispose()
Catch ex As Exception

MsgBox("数据读取失败:" & Chr(10) & "错误代码:" & Err.Number & Chr(10) & "错误分析:" & ex.Message, MsgBoxStyle.OkOnly + vbInformation, "提示信息")
End Try
End Sub
#End Region

回答3:

Dim con As New ADODB.Connection
Dim rs As New ADODB.Recordset
con.Open "provider=Microsoft.Jet.OLEDB.4.0;data source=" & App.Path & "\database.mdb;Jet OLEDB:Database password=;persist security info=false"
rs.Open "select * from table where usename=" & text_username.text, con, adOpenKeyset, adLockOptimistic
if rs("password")= text_password.text then
otherform.show
unload me
else
msgbox "用户名或密码错误!"
exit sub
end if
rs.close
con.close

回答4:

//放两个输入框分别输入用户名和密码,并在输入后分别存在两个定义好的变量里。
//用DAO访问数据库也行,但你这个功能简单就直接用控件好了。放个DATA控件和两个文本框在窗口里,设定属性并都设成隐藏的,程序运行时这两个文本框里的不就是你数据库里的用户名和密码嘛,判断一下就可以了。
//如果用DAO,先定义空间,数据库,记录集等。然后取值就可以了。
如:yonghuming=database.recordset.fields("用户名").value
mima=database.recordset.fields("密码").value
//点确定后转换到另一个窗体,判断就可以了。如果输入正确那么 FORM_MAIN.SHOW,同时自身这个窗口就FORM_LOGIN.HIDE,如果输入错误那么就清空重新填。挺好实现的。

回答5:

数据库麻烦,直接读取文本多好啊