| 订阅 | 在线投稿
分享
 
 
 

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
󰈣󰈤
 
 
 
>>返回首页<<
 
 热帖排行
 
 
静静地坐在废墟上,四周的荒凉一望无际,忽然觉得,凄凉也很美
©2005- 王朝网络 版权所有