| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 3356 人关注过本帖
标题:根据登录的用户名密码搜索出ACCESS数据库中这一列的信息并分别显示到4个Lab ...
只看楼主 加入收藏
wangyiaihu
Rank: 1
等 级:新手上路
帖 子:96
专家分:0
注 册:2020-4-22
结帖率:100%
收藏
已结贴  问题点数:15 回复次数:17 
根据登录的用户名密码搜索出ACCESS数据库中这一列的信息并分别显示到4个Label的Caption中。
图片附件: 游客没有浏览图片的权限,请 登录注册
程序代码:
Private Sub Command1_Click()
'将数据库里的信息显示到LABEL中,筛选条件是根据登录时的用户密码,获取它相应的这一列信息

Dim conn1 As New ADODB.Connection
Dim rs1 As New ADODB.Recordset
conn1.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\Aging.mdb " 'a.mdb是ACCESS数据库保存在程序目录下
rs1.Open "Select * From 注册 Where 用户='" & Form1.Text1.Text & "' and 密码='" & Form1.Text2.Text & "'", cn, 2, 3

Form3.Label1.Caption = rs1!用户
Form3.Label2.Caption = rs1!权限
Form3.Label4.Caption = rs1!所属
Form3.Label3.Caption = rs1!SHIFT别



rs1.Close
conn1.Close
Set rs1 = Nothing
Set conn1 = Nothing

搜索更多相关主题的帖子: 密码 登录 Caption 数据库 信息 
2020-04-23 11:15
wangyiaihu
Rank: 1
等 级:新手上路
帖 子:96
专家分:0
注 册:2020-4-22
收藏
得分:0 
想要实现这样的功能,请教各位大神指教,


补充下:
当前界面是FORM3,
登录界面是FORM1,

[此贴子已经被作者于2020-4-23 11:21编辑过]

2020-04-23 11:16
ZHRXJR
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:125
帖 子:1034
专家分:5519
注 册:2016-5-10
收藏
得分:0 
MsgBox "登录成功!", 64, "已经登录!"
            
            RS.Close
            Set RS = Nothing
            cn.Close
            Set cn = Nothing
            Unload Me
            Form3.Show
登录成功后直接跳转到 Form3 界面,因此在 Form_Load() 事件中直接在标签最后显示数据就可以了,不需要在按钮事件中显示
程序代码:
Dim conn1 As New ADODB.Connection
Dim rs1 As New ADODB.Recordset    '二个对象在界面通用部分声明,不需要在每个过程中都声明

Private Sub Form_Load()
conn1.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\Aging.mdb " 'a.mdb是ACCESS数据库保存在程序目录下
rs1.Open "Select * From 注册 Where 用户='" & Form1.Text1.Text & "' and 密码='" & Form1.Text2.Text & "'", cn, 2, 3   '这个语句好像有问题
    Label1.Caption = rs1!用户
    Label2.Caption = rs1!权限
    Label4.Caption = rs1!所属
    Label3.Caption = rs1!SHIFT别
    '.......................
rs1.Close
conn1.Close
Set rs1 = Nothing
Set conn1 = Nothing
End Sub



[此贴子已经被作者于2020-4-23 11:40编辑过]


请不要选我!!!
2020-04-23 11:38
wangyiaihu
Rank: 1
等 级:新手上路
帖 子:96
专家分:0
注 册:2020-4-22
收藏
得分:0 
回复 3楼 ZHRXJR
有问题的那条该怎么修改啊?
图片附件: 游客没有浏览图片的权限,请 登录注册


[此贴子已经被作者于2020-4-23 11:53编辑过]

2020-04-23 11:48
ZHRXJR
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:125
帖 子:1034
专家分:5519
注 册:2016-5-10
收藏
得分:15 
rs1.Open "Select * From 注册 Where 用户='" & Form1.Text1.Text & "' and 密码='" & Form1.Text2.Text & "'", cn, 2, 3   '这个语句好像有问题
在Form1 界面登录成功后已经关闭了并才内存清除了 Form1 界面,因此再次调用 Form1.Text1.Text 控件的值是不行的,在程序中添加一个模块,不是类模块,在模块中声明二个变量,就是程序级变量
程序代码:
Public YHMC As String '= RS("用户名")
Public YHMM As String '= RS("密码")
Public conn1 As New ADODB.Connection    '数据库连接对象
Public rs1 As New ADODB.Recordset      '记录集对象
'在模块中声明后任何界面将可以调用

Sub KKK(conn1)
'连接数据库,在模块中的过程,其他界面调用这个过程就可以
  conn1.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\Aging.mdb "
End Sub

在登录时:
            
程序代码:
MsgBox "登录成功!", 64, "已经登录!"
            YHMC = rs1!用户
            YHMM = rs1!密码    '给公用变量赋值,增加这二个语句
            rs1.Close
            Set rs1 = Nothing
            cn.Close
            Set cn = Nothing
            Unload Me
            Form3.Show

在登录成功后将用户名、用户密码赋值给这二个变量,在 Form3 界面直接调用变量就可以。
rs1.Open "Select * From 注册 Where 用户='" & YHMC & "' and 密码='" & YHMM & "'", cn, 2, 3


[此贴子已经被作者于2020-4-23 12:08编辑过]


请不要选我!!!
2020-04-23 12:07
wangyiaihu
Rank: 1
等 级:新手上路
帖 子:96
专家分:0
注 册:2020-4-22
收藏
得分:0 
回复 5楼 ZHRXJR
刚刚试了,达不到效果,还是空白,而且提示语法错误,
图片附件: 游客没有浏览图片的权限,请 登录注册

图片附件: 游客没有浏览图片的权限,请 登录注册


[此贴子已经被作者于2020-4-23 13:24编辑过]

2020-04-23 12:47
ZHRXJR
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:125
帖 子:1034
专家分:5519
注 册:2016-5-10
收藏
得分:0 
什么地方出错,你的图片看不出来。将你的FORM3的代码给我,应该是这个界面出错了吧?

请不要选我!!!
2020-04-23 13:34
wangyiaihu
Rank: 1
等 级:新手上路
帖 子:96
专家分:0
注 册:2020-4-22
收藏
得分:0 
回复 7楼 ZHRXJR
程序代码:

Private Sub Form_Load()
Form3.Image4.Picture = Form2.Image7.Picture

Form3.Image1.Picture = Form2.Image8.Picture

Form3.Image2.Picture = Form2.Image10.Picture

Form3.Image3.Picture = Form2.Image12.Picture

Form3.Image5.Picture = Form2.Image14.Picture

Form3.Image6.Picture = Form2.Image16.Picture

Form3.Image7.Picture = Form2.Image18.Picture

Form3.Image8.Picture = Form2.Image20.Picture

Form3.Image9.Picture = Form2.Image20.Picture

Form3.Image10.Picture = Form2.Image22.Picture

Form3.Image11.Picture = Form2.Image24.Picture

Form3.Image12.Picture = Form2.Image26.Picture

Form3.Image13.Picture = Form2.Image28.Picture


Form3.Label5.Caption = Date

Form3.Label6.Caption = Time


rs1.Open "Select * From 注册 Where 用户='" & YHMC & "' and 密码='" & YHMM & "'", cn, 2, 3



End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Form3.Image1.Picture = Form2.Image8.Picture

Form3.Image2.Picture = Form2.Image10.Picture

Form3.Image3.Picture = Form2.Image12.Picture

Form3.Image5.Picture = Form2.Image14.Picture

Form3.Image6.Picture = Form2.Image16.Picture

Form3.Image7.Picture = Form2.Image18.Picture

Form3.Image8.Picture = Form2.Image20.Picture

Form3.Image9.Picture = Form2.Image20.Picture

Form3.Image10.Picture = Form2.Image22.Picture

Form3.Image11.Picture = Form2.Image24.Picture

Form3.Image12.Picture = Form2.Image26.Picture

Form3.Image13.Picture = Form2.Image28.Picture


End Sub

Private Sub Image1_Click()
Form6.Show
Form3.Hide

End Sub

Private Sub Image1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Form3.Image1.Picture = Form2.Image9.Picture
Form3.Image2.Picture = Form2.Image10.Picture



End Sub

Private Sub Image10_Click()
Form3.Hide

Form4.Show

End Sub

Private Sub Image10_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Form3.Image10.Picture = Form2.Image23.Picture

End Sub

Private Sub Image11_Click()
Form9.Show
Form3.Hide

End Sub

Private Sub Image11_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Form3.Image11.Picture = Form2.Image25.Picture

End Sub

Private Sub Image12_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Form3.Image12.Picture = Form2.Image27.Picture

End Sub

Private Sub Image13_Click()


Form3.Hide
Form1.Show
Form1.Text1.Text = ""
Form1.Text2.Text = ""
Form1.Text1.SetFocus



End Sub

Private Sub Image13_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Form3.Image13.Picture = Form2.Image29.Picture

End Sub

Private Sub Image2_Click()
Form7.Show
Form3.Hide

End Sub

Private Sub Image2_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Form3.Image2.Picture = Form2.Image11.Picture
'Form3.Image1.Picture = Form2.Image8.Picture
End Sub

Private Sub Image3_Click()
Form5.Show
Form3.Hide


End Sub

Private Sub Image3_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Form3.Image3.Picture = Form2.Image13.Picture
End Sub

Private Sub Image4_Click()
End

End Sub

Private Sub Image5_Click()
Form6.Show
Form3.Hide
End Sub

Private Sub Image5_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Form3.Image5.Picture = Form2.Image15.Picture

End Sub

Private Sub Image6_Click()
Form6.Show
Form3.Hide
End Sub

Private Sub Image6_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Form3.Image6.Picture = Form2.Image17.Picture

End Sub

Private Sub Image7_Click()
Form8.Show
Form3.Hide

End Sub

Private Sub Image7_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Form3.Image7.Picture = Form2.Image19.Picture

End Sub

Private Sub Image8_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Form3.Image8.Picture = Form2.Image21.Picture

End Sub

Private Sub Image9_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Form3.Image9.Picture = Form2.Image21.Picture

End Sub

Private Sub Toolbar1_ButtonClick(ByVal Button As MSComctlLib.Button)

End Sub

Private Sub Timer1_Timer()
Form3.Label5.Caption = Date

Form3.Label6.Caption = Time
End Sub
2020-04-23 13:42
ZHRXJR
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:125
帖 子:1034
专家分:5519
注 册:2016-5-10
收藏
得分:0 

请不要选我!!!
2020-04-23 16:05
wangyiaihu
Rank: 1
等 级:新手上路
帖 子:96
专家分:0
注 册:2020-4-22
收藏
得分:0 
回复 9楼 ZHRXJR
我觉得是不是我的思路就错了,
是不是可以这样,在RORM3里面建立一个隐藏的TEXT,在FORM1登录时,将FORM1.TEXT内容传给FORM3.TEXT,
在LOADING FOrmM时,再根据这个text内容进行查询并显示到LABEL里面,

这方案怎么样?
2020-04-23 16:49
快速回复:根据登录的用户名密码搜索出ACCESS数据库中这一列的信息并分别显示到4 ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.033188 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved