vb登录界面设计代码(vb用户登录界面代码)
关于VB设计中一个用户登录界面的代码
我好像看出来一点问题,,,
Adodc1.Recordset.Fields(1).Value对应是应该是数据库里的“密码”这个字段。
而你是用Adodc1.Recordset.Fields(1).Value
Combo1.Text
进行比较,肯定是比不来出什么正确的结果的,它俩天生就不相等。所以程序会继续向下运行。
用户名应该
对应Adodc1.Recordset.Fields(0).Value
vb用户登录界面代码
送给你一段现存的登录代码:
Option Explicit
Private Function Selectsql(SQL As String) As ADODB.Recordset '返回ADODB.Recordset对象
Dim ConnStr As String
Dim Conn As ADODB.Connection
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
Set Conn = New ADODB.Connection
'On Error GoTo MyErr:
ConnStr = "Provider=SQLOLEDB.1;Persist Security Info=True;User ID=sa;Password=001234;Initial Catalog=Mydatabase;Data Source=MERRYCHINA" '这是连接SQL数据库的语句
Conn.Open ConnStr
rs.CursorLocation = adUseClient
rs.Open Trim$(SQL), Conn, adOpenDynamic, adLockOptimistic
Set Selectsql = rs
'Exit Function
'MyErr:
'Set rs = Nothing
'Set Conn = Nothing '释放相关的系统资源
'MsgBox Err.Description, vbInformation, "系统提示" '显示出错信息
End Function
Private Sub Form_Load()
Dim SQL As String
Dim rs As ADODB.Recordset
Dim X As Long
On Error GoTo Err_box
SQL = " select * from A用户表 ORDER BY ID"
Set rs = Selectsql(SQL)
If rs.RecordCount 0 Then
rs.MoveFirst
For X = 1 To rs.RecordCount
Combo1.AddItem rs.Fields("姓名").Value
rs.MoveNext
Next X
Combo1.ListIndex = 0
End If
rs.Close
Exit Sub
Err_box:
End Sub
Private Sub Command1_Click()
Dim SQL As String
Dim rs As ADODB.Recordset
If Text1.Text = "" Then
MsgBox "请输入口令!", 64, "提示"
Text1.SetFocus
Exit Sub
End If
If Combo1.Text = "" Then
MsgBox "请选择帐号!", 64, "提示"
Combo1.SetFocus
Exit Sub
End If
SQL = "SELECT * FROM A用户表 WHERE 姓名='" Combo1.Text "' AND 密码='" Text1.Text "' "
Set rs = Selectsql(SQL)
If rs.RecordCount 0 Then
Form1.Show
Unload Me
Else
MsgBox "口令不对,请重新输入!", 64, "提示"
Text1.SetFocus
End If
End Sub
'**********************************************************************
'说明:1) 在工程中引用Microsoft ActiveX Data Objects 2.8 Library ,其它版本也行如:2.0
' 2) 在窗体中加Texe1.text(文本框控件),Combo1.text(组合框控件),Command1(命令按钮)各一个
' 3) 在SQL Server2000中创建数据库"MyDatabase",新建表"A用户表",表中包含"ID,姓名,密码"等字段,然后将以上代码复制,OK搞定
VB程序设计 用户登陆界面代码
1.楼上的方法没有必要,一是调用String类型的属性调用ToString方法没有意义,二是应该不是没去空字符的原因,所以Trim应该不能解决问题
2.字段好像Username是关键字(记不清了,呵呵),改为[UserName]试试
3.不知道你的SQL代码是否有误。
4.在检查用户名是否存在的时候,建议用SqlCommand对象的ExecuteScaler方法以节省开销
vb用户怎么登录界面?用户登陆的代码是多少?
vb登陆程序源代码
你可以这样做建一个模块在里面输入下列
Public conn As ADODB.Connection
Sub main()
Set conn = New ADODB.Connection
conn.ConnectionString = "Provider=SQLOLEDB.1;Persist Security Info=False;" _
+ "User ID=sa;password=sa;Initial Catalog=您的数据库名;Data Source=127.0.0.1"
conn.Open
from1.Show ’登录界面
End Sub
再在登录界面“确定”下写入如下代码:
Private Sub Command1_Click()
If id.Text = "" Then
MsgBox "用户名不能为空!", vbOKOnly + vbInformation, "友情提示"
id.SetFocus
Exit Sub
End If
If password.Text = "" Then
MsgBox "密码不能为空!", vbOKOnly + vbInformation, "友情提示"
password.SetFocus
Exit Sub
End If
Dim strSQl As String
strSQl = "select * from Users where users_name='" Trim$(id.Text) "' and password='" Trim$(password.Text) "' "
Dim str As New ADODB.Recordset
Set str = New ADODB.Recordset
str.CursorLocation = adUseClient
str.Open strSQl, conn, adOpenStatic, adLockReadOnly
With str
If .State = adStateOpen Then .Close
.Open strSQl
If .EOF Then
Try_times = Try_times + 1
If Try_times = 3 Then
MsgBox "您已经三次尝试进入本系统,均不成功,系统将自动关闭", vbOKOnly + vbCritical, "警告"
Unload Me
Else
MsgBox "对不起,用户名不存在或密码错误 !", vbOKOnly + vbQuestion, "警告"
id.SetFocus
id.Text = ""
password.Text = ""
End If
Else
Unload Me
Form2.Show ’登录进入的另一个界面
End If
End With
End Sub
VB设置用户和密码登录界面设计及代码 我是新手哦 先谢个
Const
Pwd="Admin"
Const
Usr="Admin"
加入两个文本框和一个按钮控件,2个文本框控件名分别为
UsrTxt
和
PwdTxt
按钮控件写代码:
if
UsrTxt
=
Usr
and
PwdTxt=Pwd
then
msgbox
"密码正确!",vbinformation,"提示"
else
msgbox
"密码错误!",vbinformation,"提示"
end
if
这是简单的密码登陆,通过更改常量在程序内部规定用户名和密码!其他的自己琢磨下或者给我发邮件
TimeDev@QQ.Com
用VB设计一个登录界面
''''''以下登录界面
Dim
t
As
Integer,
s
As
Integer
Private
Sub
Form_Load()
t
=
s
=
10
Timer1.Interval
=
1000
Timer1.Enabled
=
False
End
Sub
Private
Sub
Command1_Click()
'确定按钮
Timer1.Enabled
=
False
s
=
10
If
Text1.Text
"经理" Or
Text2.Text
"12345"
Then
t
=
t
+
1
If
t
=
3
Then
MsgBox
"你无权使用本系统",
,
"帐号错误"
Else
MsgBox
"帐号错误,再试一次",
,
"帐号错误"
End
If
Else
Form2.Show
Unload
Me
End
If
End
Sub
Private
Sub
Command2_Click()
'退出按钮
End
End
Sub
Private
Sub
Timer1_Timer()
'计时器
s
=
s
-
1
If
s
=
Then
Timer1.Enabled
=
False
MsgBox
"你无权使用本系统",
,
"帐号错误"
Unload
Me
End
If
End
Sub
Private
Sub
Text_GotFocus()
Timer1.Enabled
=
True
End
Sub
'''''''以下Form2窗体
Private
Sub
Command1_Click()
'返回按钮
Form1.Show
Unload
Me
End
Sub