| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 854 人关注过本帖
标题:[求助]数据从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
快速回复:[求助]数据从excel到access的转换问题
数据加载中...
 
   



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

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