可以用ADOX来做:'引用ADOX(工程/引用/Microsoft ADO Ext. 2.X For DLL and Security) Private Sub Form_Load() Dim cat As New ADOX.Catalog cat.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\Test.mdb;User Id=admin;Password=;" cat.Tables("table1").Columns.Append "字段名", ADOX.DataTypeEnum.adLongVarBinary ' 给Table1添加OLE字段 Set cat.ActiveConnection = Nothing End Sub
Dim objCat As New ADOX.Catalog Dim objTbl As New ADOX.Table objCat.ActiveConnection = mADODBConnection '' Open the catalog With objTbl .Name = "您的TABLENAME" .Columns.Append "您的OLE字段", adLongVarBinary .Columns("您的OLE字段").Attributes = adColNullable End With ' Add the new table to the database. objCat.Tables.Append objTbl Set objCat = Nothing Resume
conn.Execute sql
conn.Execute sql
Private Sub Form_Load()
Dim cat As New ADOX.Catalog
cat.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\Test.mdb;User Id=admin;Password=;"
cat.Tables("table1").Columns.Append "字段名", ADOX.DataTypeEnum.adLongVarBinary ' 给Table1添加OLE字段
Set cat.ActiveConnection = Nothing
End Sub
1.先判断database文件存在?若否,创建它。
2。判断Table存在?若否,创建它。
3。判断一个字段是否存在?若否创建它。
怎样判断呢?试图打开它,若ERROR,就创建。
DAO先定义TableDef。用CreateTableDef,然后用Append和CreateField
ADO先定义ADOX.Catalog和ADOX.Table。
Dim objTbl As New ADOX.Table
objCat.ActiveConnection = mADODBConnection '' Open the catalog
With objTbl
.Name = "您的TABLENAME"
.Columns.Append "您的OLE字段", adLongVarBinary
.Columns("您的OLE字段").Attributes = adColNullable
End With ' Add the new table to the database.
objCat.Tables.Append objTbl
Set objCat = Nothing
Resume