问个低级vb+access数据库问题。

nonplus 2006-10-17 04:28:59
我想做个简单的用户名登陆界面,用ACCESS数据库。可是我不知道怎么从打开vb程序开始建立数据库连接。希望用ADO这种方式,听说灵活性大,请大家帮忙,在线等,谢谢。
...全文
219 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
nonplus 2006-10-18
  • 打赏
  • 举报
回复
就拿HHLADN(I Want to exceed you) 的例子来说吧,我新建立一个工程。添加一个按扭和两个输入框。我也把database.mdb创建好了,然后我把代码复制进去。
Private Sub Command1_Click()

Set conn = New ADODB.Connection
'ipaddress = "192.168.0.1"

'Str = "provider=microsoft.jet.OLEDB.4.0;Data source=\\" & ipaddress & "\database$\database.mdb"
Str = "provider=microsoft.jet.OLEDB.4.0;Data source=" & App.Path & "\database.mdb"

conn.Open Str
Set asd = New ADODB.Recordset
asd.Open sql, conn, adOpenKeyset, adLockBatchOptimistic
End Sub


可是第一句 Set conn = New ADODB.Connection 都过不去,这是什么原因?怎么做才能通过。
程序员老干部 2006-10-18
  • 打赏
  • 举报
回复
用楼上的关键代码
HHLADN 2006-10-18
  • 打赏
  • 举报
回复
'connect sql server 2000
'-----------------------------------
Private Sub Command1_Click()
Dim conn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim connect As String
Set conn = New ADODB.Connection
Set rs = New ADODB.Recordset

connect = "Driver={sql server};server=10.3.163.9;uid=sa;pwd=;database=barcode"
conn.ConnectionTimeout = 30
conn.Open connect
rs.Open "select * from defectcode", conn, 1, 1

Set DataGrid1.DataSource = rs
DataGrid1.Refresh
End Sub

'connect access 2000
'------------------------------------
Set conn = New ADODB.Connection
ipaddress = "192.168.0.1"

str = "provider=microsoft.jet.OLEDB.4.0;Data source=\\" & ipaddress & "\database$\database.mdb"
'str = "provider=microsoft.jet.OLEDB.4.0;Data source=" & App.Path & "\database.mdb"

conn.Open str
Set asd = New ADODB.Recordset
asd.Open sql, conn, adOpenKeyset, adLockBatchOptimistic
boovo 2006-10-18
  • 打赏
  • 举报
回复
Dim Rst As New ADODB.Recordset

sql = "select * from employee where 用户名='" & txtuser.Text & "'"
Rst.Open sql, conn, adOpenKeyset, adLockPessimistic
If Rst.EOF = True Then
MsgBox "对不起,该用户不存在", vbOKOnly + vbExclamation, ""
txtuser.SetFocus
Else
If Rst.Fields(1) = txtpwd.Text Then
userID = txtuser.Text
userpow = Rst.Fields(2)
Rst.Close
Unload Me
Form1.Show

提出了重点内容
feiyun0112 2006-10-17
  • 打赏
  • 举报
回复
风景区售票系统(VB+ACCESS)
http://www.codesky.net/showhtml/7597.htm

*****************************************************************************
欢迎使用CSDN论坛阅读器 : CSDN Reader(附全部源代码)
http://www.cnblogs.com/feiyun0112/archive/2006/09/20/509783.html
mustudent 2006-10-17
  • 打赏
  • 举报
回复
看了不太明白,而且我少做修改后就提示编译不能通过,有好多问题,所以我想从正确途径来学习。
//正确途径 就是先买本书看看
ftvbftvbq 2006-10-17
  • 打赏
  • 举报
回复
Option Explicit
Dim cnt As String '记录确定次数

Private Sub Command1_Click()
Dim sql As String
Dim Rst As New ADODB.Recordset
If txtuser.Text = "" Then
MsgBox "对不起,没有这个用户!", vbOKOnly + vbExclamation, ""
txtuser.SetFocus
Else
sql = "select * from employee where 用户名='" & txtuser.Text & "'"
Rst.Open sql, conn, adOpenKeyset, adLockPessimistic
If Rst.EOF = True Then
MsgBox "对不起,该用户不存在", vbOKOnly + vbExclamation, ""
txtuser.SetFocus
Else
If Rst.Fields(1) = txtpwd.Text Then
userID = txtuser.Text
userpow = Rst.Fields(2)
Rst.Close
Unload Me
Form1.Show
Else
MsgBox "密码不正确", vbOKOnly + vbExclamation, ""
txtpwd.SetFocus
End If
End If
End If
cnt = cnt + 1
If cnt = 3 Then
Unload Me
End If
Exit Sub
End Sub
Private Sub Form_Load()
login.Top = (Screen.Height - login.Height) / 2
login.Left = (Screen.Width - login.Width) / 2
Dim connectionstring As String
connectionstring = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + App.Path + "\hospital.mdb;Persist Security Info=False"
conn.Open connectionstring
cnt = 0
End Sub

Private Sub Picture1_Click()

End Sub

Private Sub Txtpwd_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 13 Then
Command1.SetFocus
End If
End Sub

Private Sub txtuser_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 13 Then
txtpwd.SetFocus
End If
End Sub
nonplus 2006-10-17
  • 打赏
  • 举报
回复
看了不太明白,而且我少做修改后就提示编译不能通过,有好多问题,所以我想从正确途径来学习。
饮水需思源 2006-10-17
  • 打赏
  • 举报
回复
在这里搜索一下也有很多资料的
mustudent 2006-10-17
  • 打赏
  • 举报
回复
直接下在一个VB ACCESS的源码程序不就可以了吗?
BAIDU OR GOOGLE应该有很多的

1,216

社区成员

发帖
与我相关
我的任务
社区描述
VB 数据库(包含打印,安装,报表)
社区管理员
  • 数据库(包含打印,安装,报表)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧