逻辑默认值 [英] Logical Default

查看:97
本文介绍了逻辑默认值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用MS-Access2000。我似乎无法设置Logical

类型字段的默认值。我开始用

Dim dbsTmp As Object''我认为它是DAO.Database

设置dbsTmp = DBEngine.OpenDatabase(CurrentProject.path&" \ data_be.mdb")


然后使用以下命令运行我的SQL ststement

dbsTmp.Execute

---- -------------------------------------------------

像这样的SQL语句有效:

" ALTER TABLE tblStudent ADD COLUMN student_number long NULL"


但是所有这些SQL陈述似乎不起作用

ALTER TABLE tblStudent ADD COLUMN student_accommodation logical -1

" ALTER TABLE tblStudent ADD COLUMN student_accommodation logical 1"

" ALTER TABLE tblStudent ADD COLUMN student_accommodation logical TRUE"

" ALTER TABLE tblStudent ADD COLUMN student_accommodation logical .T。"


-------------------------------------------------- ----

谁能告诉我如何设置逻辑字段的默认值?


谢谢

Dominic

I am using MS-Access2000. I can''t seem to set the default values for Logical
type fields. I start with
Dim dbsTmp As Object '' I think it''s DAO.Database
Set dbsTmp = DBEngine.OpenDatabase(CurrentProject.path & "\data_be.mdb")

and then use the following to run my SQL ststement
dbsTmp.Execute
-----------------------------------------------------
Something like this SQL statement works:
"ALTER TABLE tblStudent ADD COLUMN student_number long NULL"

But all of these SQL statements don''t seem to work
"ALTER TABLE tblStudent ADD COLUMN student_accommodation logical -1"
"ALTER TABLE tblStudent ADD COLUMN student_accommodation logical 1"
"ALTER TABLE tblStudent ADD COLUMN student_accommodation logical TRUE"
"ALTER TABLE tblStudent ADD COLUMN student_accommodation logical .T."

------------------------------------------------------
Can anyone tell me how to set the default value for a logical field?

Thanks
Dominic

推荐答案

尝试这样的事情:


strSql =" ALTER TABLE tblStudent ADD COLUMN student_accommodation YESNO

DEFAULT True;"

CurrentProject.Connection.Execute strSql


重要的是用ADO代码执行字符串。


-1也应该工作。


-

Allen Browne - 微软MVP。西澳大利亚珀斯

访问用户提示 - http:// allenbrowne .com / tips.html

回复群组,而不是mvps dot org的allenbrowne。


" Dominic Vella" < do *********** @ optusnet.com.auwrote in message

news:47 ***************** ******@news.optusnet.com.a u ...
Try something like this:

strSql = "ALTER TABLE tblStudent ADD COLUMN student_accommodation YESNO
DEFAULT True;"
CurrentProject.Connection.Execute strSql

The important thing is executing the string with ADO code.

-1 should also work.

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Dominic Vella" <do***********@optusnet.com.auwrote in message
news:47***********************@news.optusnet.com.a u...

>我正在使用MS-Access2000。我似乎无法设置
逻辑类型字段的默认值。我开始用

Dim dbsTmp As Object''我认为它是DAO.Database

设置dbsTmp = DBEngine.OpenDatabase(CurrentProject.path&

" \ data_be.mdb")


然后使用以下命令运行我的SQL ststement

dbsTmp.Execute

---------------------------------------------- -------

像这样的SQL语句有效:

" ALTER TABLE tblStudent ADD COLUMN student_number long NULL"


但是所有这些SQL语句似乎都不起作用

ALTER TABLE tblStudent ADD COLUMN student_accommodation logical -1

" ALTER TABLE tblStudent ADD COLUMN student_accommodation logical 1"

" ALTER TABLE tblStudent ADD COLUMN student_accommodation logical TRUE"

" ALTER TABLE tblStudent ADD COLUMN student_accommodation logical .T。


------------------------------------------ ------ ------

谁能告诉我如何设置逻辑字段的默认值?
>I am using MS-Access2000. I can''t seem to set the default values for
Logical type fields. I start with
Dim dbsTmp As Object '' I think it''s DAO.Database
Set dbsTmp = DBEngine.OpenDatabase(CurrentProject.path &
"\data_be.mdb")

and then use the following to run my SQL ststement
dbsTmp.Execute
-----------------------------------------------------
Something like this SQL statement works:
"ALTER TABLE tblStudent ADD COLUMN student_number long NULL"

But all of these SQL statements don''t seem to work
"ALTER TABLE tblStudent ADD COLUMN student_accommodation logical -1"
"ALTER TABLE tblStudent ADD COLUMN student_accommodation logical 1"
"ALTER TABLE tblStudent ADD COLUMN student_accommodation logical TRUE"
"ALTER TABLE tblStudent ADD COLUMN student_accommodation logical .T."

------------------------------------------------------
Can anyone tell me how to set the default value for a logical field?


感谢您的回复。


它没有像我收到''语法那样工作ALTER TABLE语句出错。''

错误


我认为可能是因为我使用的是DAO而不是ABODB,所以我

尝试了这个:


Dim cnn As New ADODB.Connection

Dim rst as new ADODB.Recordset

>
''打开连接。

设置cnn =新ADODB.Connection

使用cnn

.Provider =" Microsoft .Jet.OLEDB.4.0"

。打开CurrentProject.path& " \ divata_be.mdb"

结束


cnn.Execute" ALTER TABLE [tblStudent] ADD COLUMN [student_accommodation]

YESNO True;"


cnn.Close

设置cnn = Nothing


我必须保留单词DEFAULT,因为它导致它'自己''数据库默认

定义''错误。

仍然,使用True,-1和1创建了字段但没有设置默认的

值。使用.T。绝对没有好处。

我认为这是逻辑字段的怪癖,其他字段类型没有任何

设置默认值的问题(我发现如此)远)。这令人沮丧

虽然。


多米尼克


" Allen Browne" < Al ********* @ SeeSig.Invalidwrote in message

news:47 ********************* ** @ per-qv1-newsreader-01.iinet.net.au ...
Thanks for the reply.

It didn''t work as in I received a ''Syntax Error in ALTER TABLE statement.''
Error

I decided it could have been because I''m using DAO instead of ABODB, so I
tried this:

Dim cnn As New ADODB.Connection
Dim rst As New ADODB.Recordset

'' Open the connection.
Set cnn = New ADODB.Connection
With cnn
.Provider = "Microsoft.Jet.OLEDB.4.0"
.Open CurrentProject.path & "\data_be.mdb"
End With

cnn.Execute "ALTER TABLE [tblStudent] ADD COLUMN [student_accommodation]
YESNO True;"

cnn.Close
Set cnn = Nothing

I had to leave the word DEFAULT out as it caused it''s own ''Database default
definition'' error.
Still, using True, -1 and 1 created the field but did not set the default
value. Using .T. was definately no good.
I think it''s a quirk with Logical fields, other field types don''t have any
problems setting the default (that I found so far). This is frustrating
though.

Dominic

"Allen Browne" <Al*********@SeeSig.Invalidwrote in message
news:47***********************@per-qv1-newsreader-01.iinet.net.au...

尝试这样的事情:


strSql =" ALTER TABLE tblStudent ADD COLUMN student_accommodation YESNO

DEFAULT True;"

CurrentProject.Connection.Execute strSql


重要的是用ADO代码执行字符串。


-1也应该有效。


-

Allen Browne - 微软MVP。西澳大利亚珀斯

访问用户提示 - http:// allenbrowne .com / tips.html

回复群组,而不是mvps dot org的allenbrowne。


" Dominic Vella" < do *********** @ optusnet.com.auwrote in message

news:47 ***************** ******@news.optusnet.com.a u ...
Try something like this:

strSql = "ALTER TABLE tblStudent ADD COLUMN student_accommodation YESNO
DEFAULT True;"
CurrentProject.Connection.Execute strSql

The important thing is executing the string with ADO code.

-1 should also work.

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Dominic Vella" <do***********@optusnet.com.auwrote in message
news:47***********************@news.optusnet.com.a u...

>>我正在使用MS-Access2000。我似乎无法设置
逻辑类型字段的默认值。我开始使用
Dim dbsTmp As Object''我认为它是DAO.Database
设置dbsTmp = DBEngine.OpenDatabase(CurrentProject.path&
" \ data_be.mdb" )

然后使用以下命令运行我的SQL ststement
dbsTmp.Execute
-------------------- ---------------------------------
像这样的SQL语句有效:
" ALTER TABLE tblStudent ADD COLUMN student_number long NULL"

但是所有这些SQL语句似乎都不起作用
ALTER TABLE tblStudent ADD COLUMN student_accommodation logical -1
ALTER TABLE tblStudent ADD COLUMN student_accommodation logical 1
" ALTER TABLE tblStudent ADD COLUMN student_accommodation logical TRUE"
ALTER TABLE tblStudent ADD COLUMN student_accommodation logical .T。

------------------------------------------------ ------
谁能告诉我如何设置逻辑字段的默认值?
>>I am using MS-Access2000. I can''t seem to set the default values for
Logical type fields. I start with
Dim dbsTmp As Object '' I think it''s DAO.Database
Set dbsTmp = DBEngine.OpenDatabase(CurrentProject.path &
"\data_be.mdb")

and then use the following to run my SQL ststement
dbsTmp.Execute
-----------------------------------------------------
Something like this SQL statement works:
"ALTER TABLE tblStudent ADD COLUMN student_number long NULL"

But all of these SQL statements don''t seem to work
"ALTER TABLE tblStudent ADD COLUMN student_accommodation logical -1"
"ALTER TABLE tblStudent ADD COLUMN student_accommodation logical 1"
"ALTER TABLE tblStudent ADD COLUMN student_accommodation logical TRUE"
"ALTER TABLE tblStudent ADD COLUMN student_accommodation logical .T."

------------------------------------------------------
Can anyone tell me how to set the default value for a logical field?



Dominic,看起来DEFAULT适用于在ADO下执行的CREATE TABLE,

但是不用ALTER TABLE。


无论如何,使用DAO在

TableDef中设置Field的DefaultProperty要简单得多。


-

Allen Browne - 微软MVP。西澳大利亚珀斯

访问用户提示 - http:// allenbrowne .com / tips.html

回复群组,而不是mvps dot org的allenbrowne。


" Dominic Vella" < do *********** @ optusnet.com.auwrote in message

news:47 ***************** ******@news.optusnet.com.a u ...
Dominic, it looks like DEFAULT works with CREATE TABLE executed under ADO,
but not with ALTER TABLE.

Much simpler to use DAO to set the DefaultProperty of the Field in the
TableDef anyway.

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Dominic Vella" <do***********@optusnet.com.auwrote in message
news:47***********************@news.optusnet.com.a u...

感谢您的回复。


它没有像我在ALTER TABLE语句中收到''语法错误那样工作。''

错误


我认为它可能是因为我正在使用DAO代替ABODB,所以我

试了这个:


Dim cnn As New ADODB.Connection

Dim rst作为新ADODB.Recordset


''打开连接。

设置cnn =新ADODB.Connection

随着cnn

.Provider =" Microsoft.Jet.OLEDB.4.0"
。打开CurrentProject.path& " \\\ data_be.mdb"

结束


cnn.Execute" ALTER TABLE [tblStudent] ADD COLUMN

[student_accommodation] YESNO True;"


cnn.Close

设置cnn = Nothing


我必须保留DEFAULT一词,因为它导致它'自己''数据库

默认定义''错误。

仍然,使用True,-1和1创建了字段但没有设置默认的

值。使用.T。绝对没有好处。

我认为这是逻辑字段的怪癖,其他字段类型没有任何

设置默认值的问题(我发现如此)远)。这令人沮丧

虽然。


多米尼克


" Allen Browne" < Al ********* @ SeeSig.Invalidwrote in message

news:47 ********************* ** @ per-qv1-newsreader-01.iinet.net.au ...
Thanks for the reply.

It didn''t work as in I received a ''Syntax Error in ALTER TABLE statement.''
Error

I decided it could have been because I''m using DAO instead of ABODB, so I
tried this:

Dim cnn As New ADODB.Connection
Dim rst As New ADODB.Recordset

'' Open the connection.
Set cnn = New ADODB.Connection
With cnn
.Provider = "Microsoft.Jet.OLEDB.4.0"
.Open CurrentProject.path & "\data_be.mdb"
End With

cnn.Execute "ALTER TABLE [tblStudent] ADD COLUMN
[student_accommodation] YESNO True;"

cnn.Close
Set cnn = Nothing

I had to leave the word DEFAULT out as it caused it''s own ''Database
default definition'' error.
Still, using True, -1 and 1 created the field but did not set the default
value. Using .T. was definately no good.
I think it''s a quirk with Logical fields, other field types don''t have any
problems setting the default (that I found so far). This is frustrating
though.

Dominic

"Allen Browne" <Al*********@SeeSig.Invalidwrote in message
news:47***********************@per-qv1-newsreader-01.iinet.net.au...

>尝试这样的事情:

strSql =" ALTER TABLE tblStudent ADD COLUMN student_accommodation
YESNO DEFAULT True;"
CurrentProject.Connection.Execute strSql

重要的是用ADO代码执行字符串。<也应该有效。

-
Allen Browne - 微软MVP。西澳大利亚州珀斯
访问用户提示 - http://allenbrowne.com/tips .html
回复群组,而不是mvps dot org的allenbrowne。

Dominic Vella < do *********** @ optusnet.com.auwrote in message
新闻:47 ********************* **@news.optusnet.com。 au ...
>Try something like this:

strSql = "ALTER TABLE tblStudent ADD COLUMN student_accommodation
YESNO DEFAULT True;"
CurrentProject.Connection.Execute strSql

The important thing is executing the string with ADO code.

-1 should also work.

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Dominic Vella" <do***********@optusnet.com.auwrote in message
news:47***********************@news.optusnet.com. au...

>>>我正在使用MS-Access2000。我似乎无法设置
逻辑类型字段的默认值。我开始使用
Dim dbsTmp As Object''我认为它是DAO.Database
设置dbsTmp = DBEngine.OpenDatabase(CurrentProject.path&
" \ data_be.mdb" )

然后使用以下命令运行我的SQL ststement
dbsTmp.Execute
-------------------- ---------------------------------
像这样的SQL语句有效:
" ALTER TABLE tblStudent ADD COLUMN student_number long NULL"

但是所有这些SQL语句似乎都不起作用
ALTER TABLE tblStudent ADD COLUMN student_accommodation logical -1
ALTER TABLE tblStudent ADD COLUMN student_accommodation logical 1
" ALTER TABLE tblStudent ADD COLUMN student_accommodation logical TRUE"
ALTER TABLE tblStudent ADD COLUMN student_accommodation logical .T。

------------------------------------------------ ------
谁能告诉我如何设置逻辑字段的默认值?
>>>I am using MS-Access2000. I can''t seem to set the default values for
Logical type fields. I start with
Dim dbsTmp As Object '' I think it''s DAO.Database
Set dbsTmp = DBEngine.OpenDatabase(CurrentProject.path &
"\data_be.mdb")

and then use the following to run my SQL ststement
dbsTmp.Execute
-----------------------------------------------------
Something like this SQL statement works:
"ALTER TABLE tblStudent ADD COLUMN student_number long NULL"

But all of these SQL statements don''t seem to work
"ALTER TABLE tblStudent ADD COLUMN student_accommodation logical -1"
"ALTER TABLE tblStudent ADD COLUMN student_accommodation logical 1"
"ALTER TABLE tblStudent ADD COLUMN student_accommodation logical TRUE"
"ALTER TABLE tblStudent ADD COLUMN student_accommodation logical .T."

------------------------------------------------------
Can anyone tell me how to set the default value for a logical field?



这篇关于逻辑默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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