不连接ACCESS,就要连接EXCEL,谁能帮我啊?
解决方案 »
- 高分求一算法:求一年中第m个星期n 所属月份
- 汗颜,请教dynamic array 一个基本的问题
- 如何获得outlook 里面接受的新邮件的标题和内容!
- 请问,在SQL2000数据库中显示0.00,该如何设置?在线等待....
- 如何在使用WEBBROWSER1的时候使用代理服务器?
- 如何在读取的文件流中加入自己的信息。
- 开一个书与mp3的ftp有兴趣的上来看看,都是PDF格式的书请大家多多up
- 我的VB源码复制到WORD里后所有汉字都成了乱码,怎么办呢?(英文WIN2000)
- 来拿分吧,超级简单
- 请问:为什么我在调用Dll时会提示在当前路径下没有此Dll呢
- mysql接连数据库问题,在线等!!!急!!!!
- 数据库中的二进制图相怎么保存在xml中?
dim ar_Tmp as new adodb.recordset
'建立与EXCEL文件的连接
with ac_Excel
.CursorLocation = adUseClient
If .State = adStateOpen Then .Close
.ConnectionString = "Data Provider=MSDASQL.1;driver=Microsoft Excel Driver (*.xls);DBQ=c:\test.xls"
.Open
.CommandTimeout = 300
end with
'打开sheet$表
If ar_Tmp.State = adStateOpen Then ar_Tmp.Close
ar_Tmp.Open " select * from [sheet1$]", ac_Excel, adOpenKeyset, adLockReadOnly
Dim Rs_db As ADODB.Recordset
Dim PathName As String
Dim strcnn As String
Dim strsql_db As String
Dim j As Integer Private Sub Form_Load()
On Error GoTo Err
PathName = "D:\WorkBook.xls" strcnn = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=false;Data Source=" & PathName & ";Extended Properties='Excel 8.0;HDR=Yes'"
Set cnn = New ADODB.Connection
cnn.Open strcnn
strsql_db = "select * from [6月$]"
cnn.Execute strsql_db
Set Rs_db = New ADODB.Recordset
Rs_db.Open strsql_db, cnn, adOpenStatic, adLockOptimistic
For j = 0 To Rs_db.RecordCount - 1 'j=1 是从excel的第二行读起
' MsgBox Rs_db.Fields(0).Value & "Null" '当j=1时,是读取第一列的数据
Rs_db.Fields(1).Value = "Hello"
' MsgBox Rs_db.Fields(2).Value & "Null"
' MsgBox Rs_db.Fields(3).Value & "Null"
' MsgBox Rs_db.Fields(4).Value & "Null"
' MsgBox Rs_db.Fields(5).Value & "Null"
' MsgBox Rs_db.Fields(6).Value & "Null"
' MsgBox Rs_db.Fields(7).Value & "Null"
Rs_db.MoveNext
Next j
Err:
Debug.Print Err.Description
End Sub需要引用ADO 2.X
我把Adodc1.ConnectionString设置为Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=" & App.Path & "\test.xls;Extended Properties='Excel 8.0;HDR=Yes'后,记录源设为2,选择好工作表,却出现 FROM子句语法错误的提示,怎么解决?
Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=" & App.Path & "\test.xls;Extended Properties='Excel 8.0;HDR=Yes'"
Adodc1.RecordSource = "select * from [Sheet1$]"
Set DataGrid1.DataSource = Adodc1
End Sub