在access 中创建库表(.net实现)
1Imports System.Data.OleDb
2
3Public Class Form1
4
5 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
6 Dim cnn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\Documents and Settings\Administrator\My Documents\mydata.mdb")
7 Dim cmd As New OleDbCommand("CREATE TABLE person (name varchar(20),sex varchar(6),id int primary key)", cnn)
8 Dim adapter As OleDbDataAdapter
9 Dim dst As New DataSet
10 Try
11 cnn.Open()
12 cmd.ExecuteNonQuery()
13 cmd.CommandText = "insert into person values('zzq','male',1)"
14 cmd.ExecuteNonQuery()
15 cmd.CommandText = "select * from person"
16 adapter = New OleDbDataAdapter(cmd)
17 adapter.Fill(dst)
18 DataGridView1.DataSource = dst.Tables(0).DefaultView
19 cnn.Close()
20 Catch ex As Exception
21 MessageBox.Show(ex.Message)
22 End Try
23 End Sub
24
25
26End Class
27
目前access中的控制命令好像只有create table,alter table,create index,还有drop 。不过网上有说可以用CREATE PROCEDURE 创建存储过程,我一直没有找到。我用的是是access 2003+Microsoft Jet 4.0 Service Pack 8
2
3Public Class Form1
4
5 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
6 Dim cnn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\Documents and Settings\Administrator\My Documents\mydata.mdb")
7 Dim cmd As New OleDbCommand("CREATE TABLE person (name varchar(20),sex varchar(6),id int primary key)", cnn)
8 Dim adapter As OleDbDataAdapter
9 Dim dst As New DataSet
10 Try
11 cnn.Open()
12 cmd.ExecuteNonQuery()
13 cmd.CommandText = "insert into person values('zzq','male',1)"
14 cmd.ExecuteNonQuery()
15 cmd.CommandText = "select * from person"
16 adapter = New OleDbDataAdapter(cmd)
17 adapter.Fill(dst)
18 DataGridView1.DataSource = dst.Tables(0).DefaultView
19 cnn.Close()
20 Catch ex As Exception
21 MessageBox.Show(ex.Message)
22 End Try
23 End Sub
24
25
26End Class
27