标题:[求助]数据从excel到access的转换问题
只看楼主
fairy1331
Rank: 1
等 级:新手上路
帖 子:63
专家分:0
注 册:2006-3-15
 问题点数:0 回复次数:0 
[求助]数据从excel到access的转换问题
以下代码为excel到access的转换,请问有什么错误,应该如何改,谢谢

Private Sub Command1_Click()

Dim cnn1 As ADODB.Connection

Dim rs1 As ADODB.Recordset

Dim i As Integer

Dim j As Integer

Dim xlApp As Excel.Application

Dim xlBook As Excel.Workbook

Dim xlSheet As Excel.Worksheet

Dim oldPointer As Integer 'used to save the current

Dim rPointer As Integer 'current saving record

Dim xlsPointer As Integer 'used to point out the position the current record saving



Set cnn1 = New ADODB.Connection

cnn1.Open "Provider=sqloledb;Data Source=TANGZL;Initial Catalog=pubs;User Id=sa;Password=sa;"

Set rs1 = New ADODB.Recordset

rs1.CursorType = adOpenKeyset

rs1.LockType = adLockOptimistic

rs1.Open "product", cnn1, , , adCmdTable





xlsPointer = 1 'the first line of Excel sheet

Set xlApp = CreateObject("Excel.Application")

xlApp.Visible = True

Set xlBook = xlApp.Workbooks.Open("D:\database\product.xls")

Set xlSheet = xlBook.Worksheets(1)

Hide



xlSheet.Columns = 6

xlSheet.Rows = 2

For i = 0 To xlSheet.Rows - 1

rs1.AddNew

For j = 0 To xlSheet.Columns - 1

rs1.Fields(i) = xlSheet.Cells(xlsPointer, i + 1)

Next j

xlsPointer = xlsPointer + 1

Next i



Set xlApp = Nothing

Set xlBook = Nothing

xlBook.Close

xlApp.Quit

End Sub
搜索更多相关主题的帖子: Dim excel access Integer 数据 
2006-04-14 12:00



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-57428-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.631598 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved