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