| 
| 
查看: 1924|回复: 25
 | 
VB link Database(MS Access) 初学--解决了!希望会VB的,进来讨论讨论。
[复制链接] |  
 |  | 
 
| 如题,希望各位能帮帮忙,教教我。 
 我是VB新手,现在要搞Assignment,可是。。。
 关于link database一事全无头绪。
 手头上有本《Programming in Visual Basic 6.0》,已在网上找了很多E-book,但还是不明白。
 找不到咧子。
 
 我现在面对的问题是。。。
 
 User enter user id and password。Then我要read database里的table,拿出和那个user id有关的data。
 Example:
 
 User ID: E0001
 Password:******
 
 逻辑上应该是Find Employee_ID,然后compare,对吗?
 
 所有data都是在同一个table的。
 Table name: Employee
 Property:Employee_ID,Employee_Name,Employee_Password
 
 用adoc1.Recordset.Find?
 谁可以解释recordset是什么吗?
 
 拜托了。。。
 
 我不懂,不是因为我没听课,不是我没温书,
 是Lecturer还没教。
  
 [ 本帖最后由 杨大侠 于 24-11-2005 12:37 AM 编辑 ]
 | 
 |  |  |  |
 
|  |  |  
|  |  | 
 |  | 
 
 
 楼主|
发表于 23-11-2005 12:27 AM
|
显示全部楼层 |  |  |  |
 
|  |  |  
|  |  | 
 |  | 
 
 发表于 23-11-2005 09:41 AM
|
显示全部楼层 
| 你起码得把你的 error message 还有 code 放上来, 那么大家才知道怎么帮你呀.  | 
 |  |  |  |
 
|  |  |  
|  |  | 
 |  | 
 
 发表于 23-11-2005 09:51 AM
|
显示全部楼层 
| 楼主用ADODC吗。。??? 要先把DATABASE TABLE LINK进ADODC先
 然后你可要用compare 可以用ADODC.recordset.field("Employee_ID") = user_id
 然后check的时候可以: if adodc.recordset.eof = true then (代表没有这ID)
 
 不然的话可以用:adodc.recordsource = <<SQL STATEMENT>>
 然后CHECK。。。!!!
 | 
 |  |  |  |
 
|  |  |  
|  |  | 
 |  | 
 
 
 楼主|
发表于 23-11-2005 12:00 PM
|
显示全部楼层 
| 这是我的source code。 
 Private Sub cmdLogin_Click()
 
 Dim str_password As String
 Dim str_ID As String
 Dim passwor As String
 Dim ID As String
 
 str_ID = txtID.Text
 str_password = txtPassword.Text
 
 If str_ID = "" Or str_password = "" Then
 MsgBox "Please key in the following fields, if you wish to procede to next page.", vbOKOnly, "Alert"
 End If
 
 dbMetrojaya.Recordset.MoveFirst
 
 Do Until dbMetrojaya.Recordset.EOF
 If dbMetrojaya.Recordset.Fields(Employee_ID).Value = str_ID And formPassword.dbMetrojaya.Recordset.Fields(Password).Value = str_password Then
 formContent.Visible = True
 Unload formPassword
 Else
 dbMetrojaya.Recordset.MoveNext
 End If
 Loop
 End Sub
 | 
 |  |  |  |
 
|  |  |  
|  |  | 
 |  | 
 
 
 楼主|
发表于 23-11-2005 12:04 PM
|
显示全部楼层 
| 原帖由 brian29002001 于 23-11-2005 09:51 AM 发表楼主用ADODC吗。。???
 要先把DATABASE TABLE LINK进ADODC先
 然后你可要用compare 可以用ADODC.recordset.field("Employee_ID") = user_id
 然后check的时候可以: if adodc.recordset.eof = true t ...
 Link database。
 是ADODC properties吗?
 我build了,record sourse也set了,command type是adCmdTable,Table也set了。
 
 到底我少了什么?
 | 
 |  |  |  |
 
|  |  |  
|  |  | 
 |  | 
 
 
 楼主|
发表于 23-11-2005 12:06 PM
|
显示全部楼层 
| 原帖由 goatstudio 于 23-11-2005 09:41 AM 发表你起码得把你的 error message 还有 code 放上来, 那么大家才知道怎么帮你呀.
  
 Run-time error '91':
 Object variable or with block variable not set
 
 请问是什么意思?
 | 
 |  |  |  |
 
|  |  |  
|  |  | 
 |  | 
 
 
 楼主|
发表于 23-11-2005 04:27 PM
|
显示全部楼层 |  |  |  |
 
|  |  |  
|  |  | 
 |  | 
 
 发表于 23-11-2005 05:32 PM
|
显示全部楼层 |  |  |  |
 
|  |  |  
|  |  | 
 |  | 
 
 
 楼主|
发表于 23-11-2005 06:00 PM
|
显示全部楼层 
| 原帖由 meemee 于 23-11-2005 05:32 PM 发表
 
 难如登天,因为你给的资料不完整。
 
 首先,你并没有POST上完整的CODING。
 第二,你有POST上ERROR MESSAGE,但你并没有说明是哪里出ERROR。如果我们随便给你一个错的决解方式,那对你也没好处,对吗?
 这是我的source code。(全部了)
 
 Private Sub cmdLogin_Click()
 
 Dim str_password As String
 Dim str_ID As String
 Dim passwor As String
 Dim ID As String
 
 str_ID = txtID.Text
 str_password = txtPassword.Text
 
 If str_ID = "" Or str_password = "" Then
 MsgBox "Please key in the following fields, if you wish to procede to next page.", vbOKOnly, "Alert"
 End If
 
 dbMetrojaya.Recordset.MoveFirst(按debug过后,这行有ERROR)(下面的我就不知道)
 
 Do Until dbMetrojaya.Recordset.EOF
 If dbMetrojaya.Recordset.Fields(Employee_ID).Value = str_ID And formPassword.dbMetrojaya.Recordset.Fields(Password).Value = str_password Then
 formContent.Visible = True
 Unload formPassword
 Else
 dbMetrojaya.Recordset.MoveNext
 End If
 Loop
 End Sub
 
 我给的资料还不够完整吗?
 对不起喽~
 不过能给的,我都给了。
 还缺什么?
 | 
 |  |  |  |
 
|  |  |  
|  |  | 
 |  | 
 
 
 楼主|
发表于 24-11-2005 12:29 AM
|
显示全部楼层 
| 新的CODE 
 Private Sub cmdLogin_Click()
 
 Dim str_password As String * 6
 Dim str_ID As String * 5
 Dim passwor As String * 6
 Dim ID As String * 5
 
 str_ID = txtID.Text
 str_password = txtPassword.Text
 
 If txtID.Text = "" Or txtPassword.Text = "" Then
 MsgBox "Please key in the following fields, if you wish to procede to next page.", vbOKOnly, "Alert"
 End If
 
 formPassword.dbMetrojaya.Refresh
 
 Do Until formPassword.dbMetrojaya.Recordset.EOF
 If formPassword.dbMetrojaya.Recordset.Fields("Employee_ID").Value = str_ID And formPassword.dbMetrojaya.Recordset.Fields("Password").Value = str_password Then
 formContent.Visible = True
 Unload formPassword
 Exit Sub
 Else
 formPassword.dbMetrojaya.Recordset.MoveNext
 End If
 Loop
 End Sub
 | 
 |  |  |  |
 
|  |  |  
|  |  | 
 |  | 
 
 
 楼主|
发表于 24-11-2005 12:35 AM
|
显示全部楼层 |  |  |  |
 
|  |  |  
|  |  | 
 |  | 
 
 
 楼主|
发表于 24-11-2005 12:43 AM
|
显示全部楼层 |  |  |  |
 
|  |  |  
|  |  | 
 |  | 
 
 发表于 24-11-2005 02:45 AM
|
显示全部楼层 |  |  |  |
 
|  |  |  
|  |  | 
 |  | 
 
 发表于 24-11-2005 08:54 AM
|
显示全部楼层 
| link database要加text box 的吗? 怎么我都不用的?
 
 杨大侠,
 抱歉,我的VB都几乎忘了,也没有时间re-call来帮你
 不过我记得,我link database是没有用到什么text box的
 
 去参考别人的方法吧。。。
 | 
 |  |  |  |
 
|  |  |  
|  |  | 
 |  | 
 
 发表于 24-11-2005 09:15 AM
|
显示全部楼层 
| 原帖由 杨大侠 于 24-11-2005 12:43 AM 发表我只是猜测罢了。
 
 真的希望有VB高手,讲解讲解。
 让晚辈们了解了解。
 
 开这帖三天了,回复的人数比我预算中差很多。
 是没人懂?仰或使大家都没空?
 还是???
 
 这论坛给我的感觉越来越不好了。
 是我多 ...
 首先... 建议你的语气应该先放暖...
 这里的人都有工作和家庭... 并不是常挂在这里解答呢.
  
 第二... 你自己可以看到了...
 你当初没有提供任何 code, 也没有 error message,
 即使后来有了, 也不完整... 这叫别人怎么帮你呢?
  
 另外... 我到现在还不知道你的解决方法是什么...
 我对你的问题现在更感到一头雾水...
 
 看着你的 code, 我只能说, 建议你用 ADODB 来解决你的问题. 好些东西都没说清楚从那里来的, 例如 dbMetrojaya.
 用 ADODB, 你可以直接写 sql 来比较 id 和 password.
 
 你可以去参考相关的资料. www.freevbcode.com 是不错的开始.
 | 
 |  |  |  |
 
|  |  |  
|  |  | 
 |  | 
 
 发表于 24-11-2005 09:46 AM
|
显示全部楼层 
| 原帖由 杨大侠 于 24-11-2005 12:43 AM 发表我只是猜测罢了。
 
 开这帖三天了,回复的人数比我预算中差很多。
 是没人懂?仰或使大家都没空?
 还是???
 
 这论坛给我的感觉越来越不好了。
 是我多 ...
 我的电脑坏了! 快来帮我修!
 >你的电脑在哪里?
 >电脑哪里出问题了?
 为什么没人帮我修电脑?
 >。。。
 噢。。。我的电脑在。。。我家里
 >。。。
 我知道出了什么问题了,记得要ON POWER 然后电脑荧幕朝向北方就可以了
 这样简单的问题都你们不。。。
 >???!!! 。。。
  >。。。!!。。。
 | 
 |  |  |  |
 
|  |  |  
|  |  | 
 |  | 
 
 发表于 24-11-2005 09:51 AM
|
显示全部楼层 |  |  |  |
 
|  |  |  
|  |  | 
 |  | 
 
 
 楼主|
发表于 24-11-2005 06:29 PM
|
显示全部楼层 
| 这是我的interface。 
 
  
 一下四个是visible true的component:
 form name =formPassword
 textbox(ID) name=txtID
 textbox(password)=txtPassword
 Login button name=cmdLogin
 
 还有两个visible false的:
 adodc name=dbmetrojaya
 textbox(就是那个我说多加下去的)name=text1
 
 [ 本帖最后由 杨大侠 于 24-11-2005 06:34 PM 编辑 ]
 | 
 |  |  |  |
 
|  |  |  
|  |  | 
 |  | 
 
 
 楼主|
发表于 24-11-2005 06:43 PM
|
显示全部楼层 
| CODE: 
 Private Sub cmdLogin_Click()
 
 Dim str_password As String
 Dim str_ID As String
 
 str_ID = txtID.Text
 str_password = txtPassword.Text
 
 If txtID.Text = "" Or txtPassword.Text = "" Then
 MsgBox "Please key in the following fields, if you wish to procede to next page.", vbOKOnly, "Alert"
 End If
 
 formPassword.dbMetrojaya.Refresh
 
 Do Until formPassword.dbMetrojaya.Recordset.EOF
 If formPassword.dbMetrojaya.Recordset.Fields("Employee_ID").Value = str_ID And formPassword.dbMetrojaya.Recordset.Fields("Password").Value = str_password Then
 formContent.Visible = True
 Unload formPassword
 Exit Sub
 Else
 formPassword.dbMetrojaya.Recordset.MoveNext
 End If
 Loop
 End Sub
 
 [ 本帖最后由 杨大侠 于 24-11-2005 06:46 PM 编辑 ]
 | 
 |  |  |  |
 
|  |  |  
|  |  |  |  | 
            本周最热论坛帖子 |