通过ADO读取Excel数据到DataGrid控制中的问题
通过ADO读取Excel数据到DataGrid控制中的问题我是这样做的:
Dim Conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim i As Integer
Dim sql As String
strname = App.Path & "\xls1.xls"
strSheetName = "sheet1"
Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=" & strname & ";Extended Properties='Excel 8.0;HDR=Yes'"
sql = "select * from [" & strSheetName & "$]"
rs.Open sql, Conn, adOpenKeyset, adLockPessimistic
Set DataGrid1.DataSource = rs
rs.Close
Conn.Close
可是运行后DataGrid控件中还是空的.什么都没有.Excel文件中明明有数据!!
研究了一天了.还没搞定.望高手解答!先谢谢了.
注:不能用其它的连接方式.只能用ADO!