| 導購 | 订阅 | 在线投稿
分享
 
 
 

ACCESS數據庫數據傳遞的方法

2008-05-18 23:55:19  編輯來源:互聯網  简体版  手機版  移動版  評論  字體: ||

一直以來,ACCESS數據庫中的申報數據在分公司與總公司之間傳遞,用EXCEL或DBASE、TXT甚至ACCESS等格式,我總覺得不太理想。最近看了一本書,不經意間發現了一個方法,使用ACCESS數據庫生成申報數據與讀入數據似乎簡單了不少,特拿出來與大家分享。同時,也希望能得到更多的指點。

附上示例:

Sub Mwrite()

On Error GoTo thiserr

Dim rs As New ADODB.Recordset

rs.Open "dlmd", CurrentProject.Connection, adOpenDynamic, adLockOptimistic, acTable

rs.Save "a:\dlmd.adtg", adPersistADTG

rs.Close

Set rs = Nothing

thisexit:

Exit Sub

thiserr:

MsgBox Err.Description

Resume thisexit

End Sub

Sub Mread()

On Error GoTo Merr

Dim i As Integer

Dim rsDe As New ADODB.Recordset

Dim rsSo As New ADODB.Recordset

rsSo.Open "a:\dlmd.adtg", "provider=mspersist"

rsDe.Open "dlmd", CurrentProject.Connection, adOpenKeyset, adLockOptimistic, acTable

Do Until rsSo.EOF

rsDe.AddNew

For i = 0 To rsSo.Fields.Count - 1

rsDe.Fields(i) = rsSo.Fields(rsDe.Fields(i).Name)

Next i

rsDe.Update

rsSo.MoveNext

Loop

rsSo.Close

rsDe.Close

Set rsSo = Nothing

Set rsDe = Nothing

Mexit:

Exit Sub

Merr:

MsgBox Err.Description

Resume Mexit

End Sub

  一直以來,ACCESS數據庫中的申報數據在分公司與總公司之間傳遞,用EXCEL或DBASE、TXT甚至ACCESS等格式,我總覺得不太理想。最近看了一本書,不經意間發現了一個方法,使用ACCESS數據庫生成申報數據與讀入數據似乎簡單了不少,特拿出來與大家分享。同時,也希望能得到更多的指點。   附上示例:   Sub Mwrite()   On Error GoTo thiserr   Dim rs As New ADODB.Recordset   rs.Open "dlmd", CurrentProject.Connection, adOpenDynamic, adLockOptimistic, acTable   rs.Save "a:\dlmd.adtg", adPersistADTG   rs.Close   Set rs = Nothing   thisexit:   Exit Sub   thiserr:   MsgBox Err.Description   Resume thisexit   End Sub   Sub Mread()   On Error GoTo Merr   Dim i As Integer   Dim rsDe As New ADODB.Recordset   Dim rsSo As New ADODB.Recordset   rsSo.Open "a:\dlmd.adtg", "provider=mspersist"   rsDe.Open "dlmd", CurrentProject.Connection, adOpenKeyset, adLockOptimistic, acTable   Do Until rsSo.EOF   rsDe.AddNew   For i = 0 To rsSo.Fields.Count - 1   rsDe.Fields(i) = rsSo.Fields(rsDe.Fields(i).Name)   Next i   rsDe.Update   rsSo.MoveNext   Loop   rsSo.Close   rsDe.Close   Set rsSo = Nothing   Set rsDe = Nothing   Mexit:   Exit Sub   Merr:   MsgBox Err.Description   Resume Mexit   End Sub
󰈣󰈤
王朝萬家燈火計劃
期待原創作者加盟
 
 
 
>>返回首頁<<
 
 
 
 
 熱帖排行
 
王朝網路微信公眾號
微信掃碼關註本站公眾號 wangchaonetcn
 
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有