谁教我能用ADO连接数据库

suncom_zhu SA  2002-03-19 01:49:19
谁能教一个第一次用VB者用ADO连接数据库,最好列出步骤。
...全文
45 点赞 收藏 4
写回复
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
shawls 2002-03-19


http://listenshaw.myetang.com/ado210.chm

你看了就直到了,m$官方资料

回复
suncom_zhu 2002-03-19
多谢,立即试试。
回复
water_j 2002-03-19
Public Sub main()

Dim conn As New ADODB.Connection
Dim cmd As New ADODB.Command
Dim rs As New ADODB.Recordset
‘步骤 1
conn.Open "DSN=pubs;uid=sa;pwd=;database=pubs"
‘步骤 2
Set cmd.ActiveConnection = conn
cmd.CommandText = "SELECT * from authors"
‘步骤 3
rs.CursorLocation = adUseClient
rs.Open cmd, , adOpenStatic, adLockBatchOptimistic
‘步骤 4
rs("au_lname").Properties("Optimize") = True
rs.Sort = "au_lname"
rs.Filter = "phone LIKE '415 5*'"
rs.MoveFirst
Do While Not rs.EOF
Debug.Print "Name: " & rs("au_fname") & " "; rs("au_lname") & _
"Phone: "; rs("phone") & vbCr
rs("phone") = "777" & Mid(rs("phone"), 5, 11)
rs.MoveNext
Loop

‘步骤 5
conn.BeginTrans

‘步骤 6 - A
On Error GoTo ConflictHandler
rs.UpdateBatch
On Error GoTo 0

conn.CommitTrans

Exit Sub

‘ 步骤 6 - B
ConflictHandler:

rs.Filter = adFilterConflictingRecords
rs.MoveFirst
Do While Not rs.EOF
Debug.Print "Conflict: Name: " & rs("au_fname"); " " & rs("au_lname")
rs.MoveNext
Loop
conn.Rollback
Resume Next

End Sub
回复
water_j 2002-03-19
ADO 教程 (VB)


Public Sub main()

Dim conn As New ADODB.Connection
Dim cmd As New ADODB.Command
Dim rs As New ADODB.Recordset
‘步骤 1
conn.Open "DSN=pubs;uid=sa;pwd=;database=pubs"
‘步骤 2
Set cmd.ActiveConnection = conn
cmd.CommandText = "SELECT * from authors"
‘步骤 3
rs.CursorLocation = adUseClient
rs.Open cmd, , adOpenStatic, adLockBatchOptimistic
‘步骤 4
rs("au_lname").Properties("Optimize") = True
rs.Sort = "au_lname"
rs.Filter = "phone LIKE '415 5*'"
rs.MoveFirst
Do While Not rs.EOF
Debug.Print "Name: " & rs("au_fname") & " "; rs("au_lname") & _
"Phone: "; rs("phone") & vbCr
rs("phone") = "777" & Mid(rs("phone"), 5, 11)
rs.MoveNext
Loop

‘步骤 5
conn.BeginTrans

‘步骤 6 - A
On Error GoTo ConflictHandler
rs.UpdateBatch
On Error GoTo 0

conn.CommitTrans

Exit Sub

‘ 步骤 6 - B
ConflictHandler:

rs.Filter = adFilterConflictingRecords
rs.MoveFirst
Do While Not rs.EOF
Debug.Print "Conflict: Name: " & rs("au_fname"); " " & rs("au_lname")
rs.MoveNext
Loop
conn.Rollback
Resume Next

End Sub

Visual Basic 教程到此结束。
回复
发动态
发帖子

1180

社区成员

VB 数据库(包含打印,安装,报表)
申请成为版主
社区公告
暂无公告