欢迎来到天天文库
浏览记录
ID:27571684
大小:81.19 KB
页数:5页
时间:2018-12-03
《vb创建access数据表字段代码》由会员上传分享,免费在线阅读,更多相关内容在学术论文-天天文库。
1、VB创建access数据表字段代码PrivateSubForm_Load()•菜单“工程”--〉n引用"--〉nMicrosoftActiveXDataObjects2.7Library"'MicrosoftADOExt.2.7forDDLadoSecurity"ewDimcatAsADOX.CatalogSetcat=NewADOX.Catalogcat.Create("Provider=Microsoft.Jet.OLEDB.4.0;DataSource:'1+App.Pathdata.mdb”+";n)MsgBox1•数据库己经创建成功!"D
2、imtblAsADOX.TableSettbl=NewADOX.Tabletbl.ParentCatalog=cattbl.Name="MyTable"1增加一个自动增长的字段DimcolAsADOX.ColumnSetcol=NewADOX.Columncol.ParentCatalog=catcol.Type=ADOX.DataTypeEnum.adlnteger*//必须先设置字段类型col.Name="idncol.Properties(HJetOLEDB:AllowZeroLength”).Value=FalsecoLPropertie$(H
3、AutoIncrementu).Value=Truetbl.Columns.Appendcol,ADOX.DataTypeEnum.adlnteger,0’增加一个文本字段Dimcol2AsADOX.ColumnSetcol2=NewADOX.Columncol2.ParentCatalog=catcol2.Name="Description”col2.Properties(nJetOLEDB:AllowZeroLength").Value=Falsetbl.Columns.Appendcol2,ADOX.DataTypeEnum.adVarChar,
4、25•增加一个货H3型字段Dimco!4AsADOX.ColumnSetcol4=NewADOX.Columncol4.ParentCatalog=catcol4.Type=ADOX.DataTypeEnum.adCurrencycol4.Name=”xx”tbl.Columns.Appendcol4,ADOX.DataTypeEnum.adCurrency1增加一个OLE字段Dimcol5AsADOX.ColumnSetcol5=NewADOX.Columnco!5.ParentCatalog=catcol5.Ipe=ADOX.DataiypeEn
5、um.adLongVarBinarycol5.Name=MOLD_FLDMtbl.Columns-Appendcol5,ADOX.DataTypeEnum.adLongVarBinary’增加一个数值型字段Dimcol3AsADOX.ColumnSetco!3=NewADOX.Columncol3.ParentCatalog=catcol3.Type=ADOX.DataTypeEnum.adDoublecol3.Name=nllHtbl.Columns.Appendcol3,ADOX.DataTypeEnum.adDoubleDimpAsADOX.Pr
6、opertyForEachpIncol3.PropertiesDebug.Printp.Name&":"&p.Value&”:'•&p.Type&&tributesNext1设置主键tbl.Keys.Append"PrimaryKey",ADOX.KeyTypeEnum.adKeyPrimary,"id",’"•,cat.Tables.AppendtblMsgBoxn数据库表:”+tbl.Name+"己经创建成功!”Settbl=NothingSetcat=NothingDimadoconAsADODB.ConnectionSetadocon=NewA
7、DODB.Connectionadocon.OpenHProvider=Micro$oft.Jet.OLEDB.4.0;DataSource:’’&App.Pathiewdata.mdb;"&nMode=ShareDenyRead
8、ShareDenyWrite;PersistSecurityFalse;JetOLEDB:DatabasePassword:"Setcat=NewADOX.CatalogSetcat.ActiveConnection=adoconFori=0Tocat.Tables.Count-1Debug.Printcat.Tables(
9、i).Name’取出表名Ifcat.Tables(i).Name=’’MyTable”Then
此文档下载收益归作者所有