Public cnn As New ADODB.Connection
Public Adodc1 As New ADODB.Recordset
Private Sub Command5_Click() Dim ex As New Excel.Application
Dim exwbook As New Excel.Workbook
Dim exsheet As New Excel.Worksheetcnn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=false;Data Source= c:\yj\1.xls;Extended Properties='Excel 9.0;HDR=Yes'"
cnn.CursorLocation = adUseClient
cnn.Open
Adodc1.Open "select * from [Sheet1]", cnn, adOpenKeyset, adLockOptimistic
Set Me.DataGrid1.DataSource = Adodc1End Sub
我想通过ADO连接EXCEL表,对EXCEL表内的数据进行数据查询操作
执行上面的代码出现错误提示
“找不到可安装的ISAM“
我的代码有什么问题吗???
Public Adodc1 As New ADODB.Recordset
Private Sub Command5_Click() Dim ex As New Excel.Application
Dim exwbook As New Excel.Workbook
Dim exsheet As New Excel.Worksheetcnn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=false;Data Source= c:\yj\1.xls;Extended Properties='Excel 9.0;HDR=Yes'"
cnn.CursorLocation = adUseClient
cnn.Open
Adodc1.Open "select * from [Sheet1]", cnn, adOpenKeyset, adLockOptimistic
Set Me.DataGrid1.DataSource = Adodc1End Sub
我想通过ADO连接EXCEL表,对EXCEL表内的数据进行数据查询操作
执行上面的代码出现错误提示
“找不到可安装的ISAM“
我的代码有什么问题吗???
解决方案 »
- 安装一个无线路由器能带十几台电脑上网,但网络收费是怎样的?
- windows api 常量定义哪里可查?
- 取得某个表一条记录的值
- 怎么得到网页的源代码呢?谢谢!在线等,马上结
- 十万火急:如何利用循环取得自定义变量中a1或a2的值
- 请教一个简单问题
- 如何连接远程(INTERNET)数据库?
- 王国荣的《数据库编程设计》是否适合我学习?在线等待...
- /////i guess the question is very easy,but i don't solve it.HELP ME.//////////
- 在删除前如何获取ACCESS数据库中表名是否存在?
- 用VB如何拦截windows “关闭windows”窗口
- 请给一个简单的猫通讯的程序,最好有详细的步骤说明和程序
這個地要換成excel 的driver,你自已找一下,我也記不請是怎麼寫的了
//去掉单引号
Adodc1.Open "select * from [Sheet1]", cnn, adOpenKeyset, adLockOptimistic
//sheet1改为sheet1$
Public Adodc1 As New ADODB.Recordset
Private Sub Command5_Click() Dim ex As New Excel.Application
Dim exwbook As New Excel.Workbook
Dim exsheet As New Excel.Worksheetcnn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=false;Data Source= c:\yj\1.xls;Extended Properties=Excel 9.0;HDR=Yes"
cnn.CursorLocation = adUseClient
cnn.Open
Adodc1.Open "select * from [Sheet1$]", cnn, adOpenKeyset, adLockOptimistic
Set Me.DataGrid1.DataSource = Adodc1End Sub是这样改嘛??
还是不行呀,去掉那个单引号???
应该是“Provider=Microsoft.Jet.OLEDB.4.0;”出了点问题
Dim xlBook As Excel.Workbook '定义工作薄类
Dim XlSheet As Excel.Worksheet '定义工作表类
Private Sub Command1_Click() '打开Excel过程
If Dir("D:\temp\excel.bz")= “”Then '判断Excel是否打开
Set xlApp = CreateObject("Excel.Application") '创建Excel应用类
xlApp.Visible = True '设置Excel可见
Set xlBook = xlApp.Workbooks.Open("D:\temp\bb.xls") '打开Excel工作薄
Set xlSheet = xlBook.Worksheets("Sheet1") '打开Excel工作表
xlSheet.Activate '激活工作表
xlSheet.Cells(1,1) = “abc” '给单元格1行驶列赋值
Public Sub main()
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\book1.xls;Persist Security Info=False;User ID=Admin;Password=;Extended properties=Excel 5.0"
cn.CursorLocation = adUseClient
cn.Open
rs.Open "SELECT * FROM [Sheet1$]", cn, adOpenDynamic, adLockBatchOptimistic
MsgBox rs.RecordCount
rs.MoveFirst
Do While rs.EOF <> True
MsgBox rs.Fields.Item(0).Name
MsgBox rs.Fields.Item(0).Value
rs.MoveNext
Loop
If rs.State <> adStateClosed Then rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing
End Sub
Adodc1.ConnectionString = "DBQ=E:\a.xls;DefaultDir=E:\;Driver={Driver do Microsoft Excel(*.xls)};DriverId=790;FIL=excel 8.0;FILEDSN=E:\a.dsn;MaxBufferSize=2048;MaxScanRows=8;PageTimeout=5;ReadOnly=1;SafeTransactions=0;Threads=3;UID=admin;UserCommitSync=Yes;"
Adodc1.RecordSource = "select * from [Sheet1$]"
Adodc1.Refresh
Set DataGrid1.DataSource = Adodc1End Sub
试试这个,本机调试成功了。