VB.NET OLEDB创建Excel数据库

2019-07-22 15:00:47 浏览数 (1)

VB.NET OLEDB创建Excel数据库

代码语言:javascript复制
Imports System.Data.OleDb

Public Class Form1
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim cnstr As String = "Provider=Microsoft.jet.OLEDB.4.0;Data Source=c:/test.xls;Extended Properties='Excel 8.0'"
        Dim cn As New OleDbConnection(cnstr)
        Dim sqlCreate As String = "CREATE TABLE vb小源码 ([序号] INTEGER,[用户名] VarChar,[密码] VarChar)"
        Dim ocmd As New OleDbCommand(sqlCreate, cn)
        '创建Excel文件
        cn.Open()
        '创建vb小源码工作表
        ocmd.ExecuteNonQuery()
        '添加数据
        ocmd.CommandText = "INSERT INTO vb小源码 VALUES(1,'VB小源码','123456')"
        ocmd.ExecuteNonQuery()
        cn.Close()
    End Sub
End Class
vba

0 人点赞