在VB中動態創建數據庫
新建工程.添加控件 對應寫上代碼
以下為引用的內容:Private Sub Command2_Click()
Dim myDB As DAO.Database
'Set myDB = DAO.OpenDatabase("d:\mydb3.mdb")
Set myDB = DAO.OpenDatabase(App.Path + "/mydb.mdb")
Dim d As String
d = "delete * from NewTable1"
myDB.Execute d
MsgBox "成功刪除全部記錄"
End Sub
Private Sub Command3_Click()
Dim myDB As DAO.Database
'Set myDB = DAO.OpenDatabase("d:\mydb3.mdb")
Set myDB = DAO.OpenDatabase(App.Path + "/mydb.mdb")
Dim e As String
e = "drop TABLE NewTable1"
myDB.Execute e
End Sub
Private Sub Form_Load()
Dim myDB As DAO.Database
'Set myDB = DAO.Workspaces(0).CreateDatabase("d:\mydb3.mdb", dbLangGeneral)
Set myDB = DAO.Workspaces(0).CreateDatabase(App.Path + "/mydb.mdb", dbLangGeneral)
Dim str_SQL As String
str_SQL = "Create Table NewTable1(Field1 Text(10),FIEld2 Short)"
myDB.Execute str_SQL
Dim a As String
a = "Insert INTO NewTable1 VALUES ('litao','21')"
myDB.Execute a
str_SQL = "Create Table NewTable2(Field1 Text(10),FIEld2 Short)"
myDB.Execute str_SQL
myDB.Close
MsgBox "成功創建mydb3.mdb數據庫外加一條記錄litao 21"
End Sub
Private Sub Command1_Click()
Dim myDB As DAO.Database
'Set myDB = DAO.OpenDatabase("d:\mydb3.mdb")
Set myDB = DAO.OpenDatabase(App.Path + "/mydb.mdb")
Dim c As String
c = "Insert INTO NewTable1 VALUES ('liqiao','20')"
myDB.Execute c
MsgBox "成功插入一條記錄liqiao 20"
End Sub