空手建立Access数据库

作者:凯旋网络来源:凯旋网络

软件说明:包含源码

说明: frmMain表单一个 中国站.长.站

Private Sub Command1_Click()

Www^Chinaz^com

On Error GoTo Err100 中国.站长站

''定义表与字段 Www_Chinaz_com

以下为引用的内容:

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 Chinaz^com

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

Www~Chinaz~com

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

''表追加
DefDatabase.TableDefs.Append DefTable

中国站长.站

MsgBox " 一切 OK , 《中国》表已经建立完成! ", VBInformation Chinaz~com

Exit Sub 中国站长.站

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

End Sub Chinaz@com

Private Sub cmdCreate_Click() Www^Chinaz^com

On Error GoTo Err100 站.长.站

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

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

中国.站.长站

Exit Sub

Www@Chinaz@com

Err100:
MsgBox "不能建立数据库! " & vbCrLf & vbCrLf & Err.Description, VBInformation 中.国站长站

End Sub Www@Chinaz@com

中国.站.长站

  • 广告推荐