AutoCAD 3DMAX C语言 Pro/E UG JAVA编程 PHP编程 Maya动画 Matlab应用 Android
Photoshop Word Excel flash VB编程 VC编程 Coreldraw SolidWorks A Designer Unity3D
 首页 > ACCESS

空手建立Access数据库

51自学网 http://www.wanshiok.com

空手建立Access数据库

程序图例

-------------------------------------

软件说明:包含源码
说明: frmMain表单一个

Private Sub Command1_Click()

On Error GoTo Err100

'定义表与字段
Dim DefDatabase As Database
Dim DefTable As TableDef, DefField As Field

Set DefDatabase = Workspaces(0).OpenDatabase(App.Path & "/VB-CODE.MDB", 0, False)
Set DefTable = DefDatabase.CreateTableDef("中国")

'dbBinary = 9
'dbBoolean = 1
'dbByte = 2
'dbChar=18
'dbDate=8
'dbInteger=3
'dbLong=4
'dbMemo=12
'dbText=10

'建立Name字段为8个字符型
Set DefField = DefTable.CreateField("Name", dbText, 8)
DefTable.Fields.Append DefField

Set DefField = DefTable.CreateField("Sex", dbText, 2)
DefTable.Fields.Append DefField

'该字段允许为空
DefField.AllowZeroLength = True
'建立Age字段为3个的常整型
Set DefField = DefTable.CreateField("Age", dbInteger, 3)
'字段追加
DefTable.Fields.Append DefField

'表追加
DefDatabase.TableDefs.Append DefTable

MsgBox " 一切 OK , 《中国》表已经建立完成! ", vbInformation

Exit Sub

Err100:
MsgBox "对不起,不能建立表。请先再建表前建立VB-CODE数据库? ", vbCritical

End Sub

Private Sub cmdCreate_Click()

On Error GoTo Err100

'建立名为 VB-CODE 的数据库
CreateDatabase "VB-CODE", dbLangGeneral

MsgBox " 一切 OK , 数据库建立完成! ", vbInformation

Exit Sub

Err100:
MsgBox "不能建立数据库! " & vbCrLf & vbCrLf & Err.Description, vbInformation

End Sub

 

 

 
上一篇:数据库设计范式  下一篇:给你的数据库文件减肥