首页 > 数据库 > Access > 正文

在VB中动态创建数据库

2024-09-07 19:03:28
字体:
来源:转载
供稿:网友

在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

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表