ASP创建ACCESS表或添加字段 |
创建一张空表: X4WZ93 http://blog.numino.net/ Sql="Create TABLE [表名]" d0MZQp http://blog.numino.net/ 创建一张有字段的表: kZUA82 http://blog.numino.net/ Sql="Create TABLE [表名]([字段名1] MEMO NOT NULL, [字段名2] MEMO, [字段名3] COUNTER NOT NULL, [字段名4] DATETIME, [字段名5] TEXT(200), [字段名6] TEXT(200)) y6kQ6A http://blog.numino.net/ 字段类型: dsEAm7 http://blog.numino.net/ 2 : "SmallInt", // 整型 BiRqQ8 http://blog.numino.net/ 3 : "Int", // 长整型 I2Xi6l http://blog.numino.net/ 4 : "Real", // 单精度型 p1bH5v http://blog.numino.net/ 5 : "Float", // 双精度型 qX1p88 http://blog.numino.net/ 6 : "Money", // 货币 5y9Y3u http://blog.numino.net/ 7 : "DateTime", // 日期时间 aJwSni http://blog.numino.net/ 11 : "Bit", // 是否 0ykdu9 http://blog.numino.net/ 13 : "TimeStamp", zSnCq5 http://blog.numino.net/ 17 : "TinyInt", // 字节 3Ohc82 http://blog.numino.net/ 72 : "UniqueIdentifier", // 同步复制 ID 31rXEp http://blog.numino.net/ 128 : "Binary", gxb65R http://blog.numino.net/ 129 : "Char", vM8XRA http://blog.numino.net/ 130 : "NChar", mwdAt1 http://blog.numino.net/ 131 : "Decimal", // 小数 N3Rtb8 http://blog.numino.net/ 133 : "DateTime", s4CPL4 http://blog.numino.net/ 135 : "SmallDateTime", wX45yX http://blog.numino.net/ 200 : "VarChar", e1ku0B http://blog.numino.net/ 201 : "Text", z8w2YV http://blog.numino.net/ 202 : "VarChar", // 文本 HC3pMm http://blog.numino.net/ 203 : "Text", // 备注 da1CSp http://blog.numino.net/ 204 : "Binary", // 二进制 2FQFtZ http://blog.numino.net/ 205 : "Image" // OLE 对象 Rkhdm5 http://blog.numino.net/ 以下字段为无编码字段(NChar、NVarchar、NText型) 98Dx0y http://blog.numino.net/ 8,128,130,202,203,204,205 wqf4cb http://blog.numino.net/ 以下字段为按当前系统内码编码的字段(Asp中可用CodePage=936纠正为gb2312内码) 1NU65q http://blog.numino.net/ 129,200,201 5T9jLo http://blog.numino.net/ 在现有的表中增加字段: dp6UbF http://blog.numino.net/ Sql="alter table [表名] add column [字段名] varchar(200)" v0ipHL http://blog.numino.net/ 修改字段类型: I9wp3p http://blog.numino.net/ Sql="alter table [表名] Alter COLUMN 字段名] varchar(50)" Ihl85D http://blog.numino.net/ 删除表: rMCB1a http://blog.numino.net/ Sql="Drop table [表名]" RVN7TL http://blog.numino.net/ 删除字段: SHJTEK http://blog.numino.net/ sql="alter table [表名] drop [字段名]" 05ZwXR http://blog.numino.net/ 修改字段:Alter TABLE [表名] Alter COLUMN [字段名] 类型(大小) NULL NFZ9Ar http://blog.numino.net/ 新建约束:Alter TABLE [表名] ADD CONSTRAINT 约束名 CHECK ([约束字段] <= '2007-1-1') F0FDIw http://blog.numino.net/ 删除约束:Alter TABLE [表名] Drop CONSTRAINT 约束名 6Cp8zr http://blog.numino.net/ 新建默认值:Alter TABLE [表名] ADD CONSTRAINT 默认值名 DEFAULT 'Gziu.CoM' FOR [字段名] f4df6L http://blog.numino.net/ 删除默认值:Alter TABLE [表名] Drop CONSTRAINT 默认值名 ZVciD0 http://blog.numino.net/ ======================================= L859Z2 http://blog.numino.net/ conn.open connstr 0nqCu0 http://blog.numino.net/ sql="alter table [tablename] add hehe char(20)" 959i44 http://blog.numino.net/ conn.execute(sql) 2oNUBz http://blog.numino.net/ response.write("添加成功") 11grYM http://blog.numino.net/ ACCESS新建数据库和表还不简单,有了表字段初始化就更简单 4iwLVI http://blog.numino.net/ ======================================= uXb93e http://blog.numino.net/ <% DS0UTC http://blog.numino.net/ session("tablen")="news" VFFA2d http://blog.numino.net/ 'news是已存在的表名 6sbfDF http://blog.numino.net/ session("fieldsn")="c" PAxnkG http://blog.numino.net/ '要添加的字段名 4lq2Tf http://blog.numino.net/ connectionstring="provider=microsoft.jet.oledb.4.0;data source="&server.MapPath("data/qq.mdb") QA0xej http://blog.numino.net/ set conn=server.createobject("adodb.connection") 0c0W6d http://blog.numino.net/ conn.OPEN connectionstring O7gtAg http://blog.numino.net/ jhsql = " Alter Table "&session("tablen")&" add column "&session("fieldsn")&" real " bI6tcE http://blog.numino.net/ conn.execute(jhsql) JItNo0 http://blog.numino.net/ %> A8jAog http://blog.numino.net/ ================================ 5qKMHb http://blog.numino.net/ 生成数据表,添加字段,其中id字段为自动增加,测试通过~~ 5PizL2 http://blog.numino.net/ Sub GenAutoIncrementFld() OKRQnj http://blog.numino.net/ set cn=server.CreateObject("ADODB.Connection") t5s3fr http://blog.numino.net/ set clx=server.CreateObject("ADOX.Column") 09uTZt http://blog.numino.net/ set cat=server.CreateObject("ADOX.Catalog") cai6gR http://blog.numino.net/ set tblnam=server.CreateObject("ADOX.Table") X2ilY8 http://blog.numino.net/ 0cAwuU http://blog.numino.net/ cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\网站制作\asp操作mdb\db\test.mdb" X4z01D http://blog.numino.net/ Set cat.ActiveConnection = cn EYQaF4 http://blog.numino.net/ tblnam.Name = "Test" 0bYqwW http://blog.numino.net/ clx.ParentCatalog = cat nF58Um http://blog.numino.net/ xP3z0T http://blog.numino.net/ clx.Type = 3 u1nq0o http://blog.numino.net/ clx.Name = "Id" UrtuqH http://blog.numino.net/ clx.Properties("AutoIncrement") = true QYS3Ab http://blog.numino.net/ tblnam.Columns.Append clx Jlk83Z http://blog.numino.net/ tblnam.Columns.Append "DataField",130,20 82j40S http://blog.numino.net/ cat.Tables.Append tblnam kJJ6E8 http://blog.numino.net/ Set clx = Nothing H1b5fE http://blog.numino.net/ Set cat = Nothing 82bslw http://blog.numino.net/ cn.Close jUKNce http://blog.numino.net/ Set cn = Nothing 6trd6K http://blog.numino.net/ End Sub cHH94P http://blog.numino.net/ call GenAutoIncrementFld B315hA http://blog.numino.net/ =================================== 1aX47g http://blog.numino.net/ 字段类型对应数值 d8jU8n http://blog.numino.net/ ''---- DataTypeEnum Values ---- ktk2ef http://blog.numino.net/ Const adEmpty = 0 woiRlo http://blog.numino.net/ Const adTinyInt = 16 STKtpo http://blog.numino.net/ Const adSmallInt = 2 6v9dO5 http://blog.numino.net/ Const adInteger = 3 1AqG4t http://blog.numino.net/ Const adBigInt = 20 5Fy9j7 http://blog.numino.net/ Const adUnsignedTinyInt = 17 MuWLuT http://blog.numino.net/ Const adUnsignedSmallInt = 18 rUPPZ4 http://blog.numino.net/ Const adUnsignedInt = 19 Abb159 http://blog.numino.net/ Const adUnsignedBigInt = 21 bG40nw http://blog.numino.net/ Const adSingle = 4 o8JSAI http://blog.numino.net/ Const adDouble = 5 TmK9B7 http://blog.numino.net/ Const adCurrency = 6 eJ5bwG http://blog.numino.net/ Const adDecimal = 14 b8c36z http://blog.numino.net/ Const adNumeric = 131 XryjT1 http://blog.numino.net/ Const adBoolean = 11 d660zN http://blog.numino.net/ Const adError = 10 mVeyn2 http://blog.numino.net/ Const adUserDefined = 132 bjck38 http://blog.numino.net/ Const adVariant = 12 2Ly9t8 http://blog.numino.net/ Const adIDispatch = 9 uCRx8H http://blog.numino.net/ Const adIUnknown = 13 uf4puI http://blog.numino.net/ Const adGUID = 72 2yHGni http://blog.numino.net/ Const adDate = 7 8aKL64 http://blog.numino.net/ Const adDBDate = 133 xeV5ie http://blog.numino.net/ Const adDBTime = 134 f6ISu0 http://blog.numino.net/ Const adDBTimeStamp = 135 VdOvWk http://blog.numino.net/ Const adBSTR = 8 N8d3VF http://blog.numino.net/ Const adChar = 129 tVAimR http://blog.numino.net/ Const adVarChar = 200 y4pBLi http://blog.numino.net/ Const adLongVarChar = 201 1yDQdR http://blog.numino.net/ Const adWChar = 130 Ki67SH http://blog.numino.net/ Const adVarWChar = 202 LbWWQ1 http://blog.numino.net/ Const adLongVarWChar = 203 H8xAuz http://blog.numino.net/ Const adBinary = 128 LeCMub http://blog.numino.net/ Const adVarBinary = 204 xfxB92 http://blog.numino.net/ Const adLongVarBinary = 205 bqFoe8 http://blog.numino.net/ Const adChapter = 136 QXcOG0 http://blog.numino.net/ Const adFileTime = 64 SUjqro http://blog.numino.net/ Const adPropVariant = 138 qg8PkL http://blog.numino.net/ Const adVarNumeric = 139 R8DE9A http://blog.numino.net/ Const adArray = &H2000
|
|