用心做好每一件事情!

【VB6笔记-01】 读取Excel绑定到DataGrid

Private Sub cmdOpen_Click()
    CommonDialog1.Filter = "Excel???t(*.xlsx)|*.xlsx"
    CommonDialog1.DialogTitle = "????"
    CommonDialog1.ShowOpen
    Me.txtFilePath.Text = CommonDialog1.FileName
    
    
    Dim DBconn As ADODB.Connection
    Dim strSQL As String
    Dim RS As ADODB.Recordset
    
    Set DBconn = New ADODB.Connection
    Set RS = New ADODB.Recordset
    DBconn.CursorLocation = adUseClient
    strSQL = "SELECT * FROM [Sheet1$]"
    DBconn.Open "provider=microsoft.ace.oledb.12.0;extended properties='Excel 12.0 Xml; imex=1'; data source=" & Me.txtFilePath.Text
    RS.Open strSQL, DBconn, adOpenDynamic, adLockOptimistic
    
    Set dgList.DataSource = RS
    dgList.AllowUpdate = True
    
    
End Sub

 

posted @ 2014-05-13 20:31  无 影  阅读(2029)  评论(0编辑  收藏  举报
作者: Allen【QQ:96966 1314】 网名:无影 出处: http://www.cnblogs.com/allen0118/ 声明: 本文版权归作者和博客园共有!转载时必须保留此段声明,且在文章页面明显位置给出原文连接。