在VB中动态创建数据库_Access数据库教程

编辑Tag赚U币
教程Tag:暂无Tag,欢迎添加,赚取U币!

推荐:在ACCESS 中调用后台存储过程
ACCESS是一个Client/Server的优秀前端开发工具,具有易学易用,界面友好,开发简单,和其他数据库接口灵活。但是,它要对大量数据处理时,速度比较慢。深圳供电局现有60万用户,下面有6个营业所

在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

分享:如何防止ACCESS数据库被下载
  昨天和animator试验了一下,把data.mdb文件改名为data.asp文件后放在wwwroot目录里。然后在IE中输入data.asp路径后,发现IE显示一片空白,右键->察看源文件,跳出记事本,将内容另存为.m

来源:模板无忧//所属分类:Access数据库教程/更新时间:2008-08-22
相关Access数据库教程