vb.net 链接Excel数据库

vb.net

'链接Excel数据库
Dim adapter As New OleDb.OleDbDataAdapter
Sub SqlServer()
    Dim Excel_SQL As String
    'Select数据库查询语句
    Excel_SQL = "SELECT * from [sheet1$]"
    Dim DB_ConnectString As String
    '链接数据库Excel链接
    DB_ConnectString = "Provider=Microsoft.Jet.OleDb.4.0;Data Source= 工作簿1.xls;Extended Properties=""Excel 5.0;HDR = Yes;IMEX=1"""
    Dim connection As New OleDb.OleDbConnection(DB_ConnectString)
    adapter.SelectCommand = New OleDb.OleDbCommand(Excel_SQL, connection)
    Dim MYDATASET As New DataSet
    adapter.Fill(MYDATASET)
    '数据显示到DataGridView窗体
    Me.DataGridView1.DataSource = MYDATASET.Tables(0)
End Sub
© 版权声明
THE END
喜欢就支持一下吧
点赞1 分享
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情代码图片