SET"必需=假"在VBScript到MS Access文件 [英] Set "Required=False" in VBScript to MS Access file

查看:172
本文介绍了SET"必需=假"在VBScript到MS Access文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现如何从传统的ASP文件中的数据并将吐出到一个新的MS Access文件,一个非常好的例子。我的一个问题是我需要的列的必需的属性设置为false,这样,如果存在该列的数据,也不会崩溃。谷歌搜索得到我的结果与不同的语法,它似乎并没有工作。如果某些可以帮我设置的属性与这个例子中,我AP preciate它。

 昏暗的供应商:供应商=microsoft.jet.oledb.4.0
暗淡DB:DB =C:\\ Documents和Settings \\ ***** \\桌面\\ foodb.mdb
昏暗的DS:DS =供应商=&放大器;提供商的放大器; 数据源=&放大器;分贝昏暗的目录:设置目录= CREATEOBJECT(adox.catalog)
catalog.create DS'创建数据库文件'常量列类型
 常量adInteger = 3'的整数
 常量adVarChar = 202'字符变量 暗淡NEW_TABLE:设置NEW_TABLE = CREATEOBJECT(adox.table)
 new_table.Name =客户
 new_table.columns.appendID,adInteger
 new_table.columns.append姓,adVarChar new_table.keys.appendpk_cust_id,1,ID'主键 catalog.Tables.Append NEW_TABLE'追加表DB 释放资源
 设置NEW_TABLE =什么
 设置目录=什么 通过这一点,现在创建DB 填充表 昏暗的康涅狄格州:康涅狄格州设置= CREATEOBJECT(adodb.connection)'创建连接
 conn.open DS的开放连接 SQL =插入到用户(ID,姓)VALUES(5,'SMITH')
 conn.Execute SQL 密切联系和资源回收
  conn.close
 康涅狄格州设置什么=


解决方案

这VBScript中做什么,我想你想要的,但它确实更简洁海事组织。

 显式的选项
昏暗的供应商:供应商=microsoft.jet.oledb.4.0
昏暗的DB:DB =C:\\ ACCESS \\ webforums \\ foodb.mdb
昏暗的DS:DS =供应商=&放大器;提供商的放大器; 数据源=&放大器;分贝
昏暗的Sql
昏暗的CREATETABLE
昏暗的目录:设置目录=的CreateObject(adox.catalog)catalog.create DS'创建数据库文件
设置目录=什么通过这一点,现在创建DB
创建和填充表康涅狄格州暗淡:康恩设置=的CreateObject(adodb.connection)'创建连接
conn.Open DS的开放连接
CREATETABLE =CREATE TABLE客户(与& _
    ID计数器约束pk_cust_id PRIMARY KEY,&放大器; _
    姓文本(255));
conn.Execute CREATETABLE
SQL =插入到用户(ID,姓)VALUES(5,'SMITH')
conn.Execute的Sql密切联系和资源回收
conn.Close
康涅狄格州设置=无

通过这种方法,对于姓字段属性包括所需=不,这是我想你想要的。

如果你的意思是要插入空到id字段,不能用id作为主键发生。主键约束将不允许使用NULL值。

I found a really nice example on how to take data from a classic ASP file and spit it out to a new MS Access file. My one problem is I need to set the "Required" property of a column to false so that if no data exists for that column, it won't crash. Googling gets me results with different syntax and it doesn't seem to work. If some can help me set the property with this example, I'd appreciate it.

dim provider : provider = "microsoft.jet.oledb.4.0"
dim db : db = "c:\Documents and Settings\*****\Desktop\foodb.mdb"
dim ds : ds = "provider=" & provider & "; data source=" & db

dim catalog:set catalog=createobject("adox.catalog")
catalog.create ds 'create db file

'const for column types
 const adInteger=3   'integer
 const adVarChar=202   'variable character

 dim new_table:set new_table=createobject("adox.table")
 new_table.Name="customer"
 new_table.columns.append "id", adInteger
 new_table.columns.append "surname", adVarChar

 new_table.keys.append "pk_cust_id", 1, "id" 'primary key

 catalog.Tables.Append new_table   'append table to DB

 'release resources
 set new_table=nothing
 set catalog=nothing

 'By this point, DB is now created

 'populate table

 dim conn: set conn=createobject("adodb.connection") 'create connection
 conn.open ds 'open connection

 sql="insert into customer (id, surname) values (5, 'smith')"
 conn.Execute sql

 'close connection and reclaim resources
  conn.close
 set conn=nothing

解决方案

This VBScript does what I think you want, but does it more concisely IMO.

Option Explicit
Dim provider: provider = "microsoft.jet.oledb.4.0"
Dim db: db = "C:\Access\webforums\foodb.mdb"
Dim ds: ds = "provider=" & provider & "; data source=" & db
Dim Sql
Dim CreateTable
Dim catalog: Set catalog = CreateObject("adox.catalog")

catalog.create ds 'create db file
Set catalog = Nothing

'By this point, DB is now created
'create and populate table

Dim conn: Set conn = CreateObject("adodb.connection") 'create connection
conn.Open ds 'open connection
CreateTable = "CREATE TABLE customer (" & _
    "id COUNTER CONSTRAINT pk_cust_id PRIMARY KEY, " & _
    "surname TEXT(255));"
conn.Execute CreateTable
Sql = "insert into customer (id, surname) values (5, 'smith')"
conn.Execute Sql

'close connection and reclaim resources
conn.Close
Set conn = Nothing

With this method, the properties for the surname field include Required = No, which is what I think you want.

If you meant you want to insert Null into the id field, that can't happen with id as primary key. The primary key constraint will not allow Null values.

这篇关于SET"必需=假"在VBScript到MS Access文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆