将表日期/时间字段更改为代码中的文本字段 [英] Change table date/time field to text field in code
本文介绍了将表日期/时间字段更改为代码中的文本字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何以编程方式,将当前数据库中的某些日期/时间字段存入当前数据库并将其类型更改为文本?
dixie
解决方案
您可以通过执行DDL查询来更改列类型。
示例:
Dim strSql As String
strSql =" ALTER TABLE MyTable ALTER COLUMN MyField TEXT(20);"
DBEngine(0)(0)。执行strSql,dbFailOnError
我很难想象这样一个场景,它会是一个好主意
使用文本类型字段来保存日期/时间数据虽然。这种方法可以解决大量问题,包括标准,排序,日期数学,无效的b $ b条目,国际格式问题等等。
-
Allen Browne - 微软MVP。西澳大利亚州珀斯。
访问用户提示 - http:// allenbrowne.com/tips.html
回复群组,而不是mvps dot org的allenbrowne。
" Dixie" <二*** @ dogmail.com>在消息中写道
news:43 ******** @ duster.adelaide.on.net ...我如何以编程方式,取一些日期/时间字段存在于当前数据库的表格中,并将其类型更改为文本?
dixie
I 我可能会采用错误的方式,但我使用带有
的TransferText导出规范来生成我需要的制表符分隔文本文件和
日期/时间字段在日期结束时附加了00:00:00。
没时间,我无法负担这个进入文本文件。我认为
如果我更改了表格,这是一个由Maketable查询生成的临时表格
生成后,日期/时间字段是文本字段
问题会消失。我相信有一个更优雅的解决方案
虽然。
dixie
" Allen Browne" <铝********* @ SeeSig.Invalid>在消息中写道
news:43 ********************** @ per-qv1-newsreader-01.iinet.net.au ...您可以通过执行DDL查询来更改列类型。
示例:
Dim strSql As String
strSql =" ALTER表MyTable ALTER COLUMN MyField TEXT(20);"
DBEngine(0)(0)。执行strSql,dbFailOnError
我很难想象它会成为一个场景好主意
使用文本类型字段来保存日期/时间数据。该方法将释放大量问题,包括标准,排序,日期数学,无效的条目,国际格式问题等。
-
Allen Browne - 微软MVP。西澳大利亚州珀斯。
访问用户提示 - http://allenbrowne.com/ tips.html
回复群组,而不是mvps dot org的allenbrowne。
Dixie <二*** @ dogmail.com>在消息中写道
新闻:43 ******** @ duster.adelaide.on.net ...我如何以编程方式,取一些日期/时间字段当前数据库中的表格并将其类型更改为文本?
dixie
简单解决方案:创建一个根据需要格式化日期的查询,并且
导出查询。
例如,您可以将其键入查询设计中的字段行:
格式([Date1],短日期)
将Date1替换为日期字段的名称。
-
Allen Browne - 微软MVP。西澳大利亚州珀斯。
访问用户提示 - http:// allenbrowne.com/tips.html
回复群组,而不是mvps dot org的allenbrowne。
" Dixie" <二*** @ dogmail.com>在消息中写道
news:43 ****** @ duster.adelaide.on.net ...我可能会以错误的方式去做,但我正在使用带有导出规范的TransferText
来生成我需要的制表符分隔文本文件
并且日期/时间字段已经在00:00:00附加了
日期。没有时间,我无法承受这个进入文本文件。
我想如果我改变了表格,这是一个临时表格,它是由一个可生成的Makoraable查询生成的日期/时间字段是
文本字段,问题会消失。我相信有一个更优雅的解决方案。
dixie
Allen Browne <铝********* @ SeeSig.Invalid>在消息中写道
新闻:43 ********************** @ per-qv1-newsreader-01.iinet.net.au ... < blockquote class =post_quotes>您可以通过执行DDL查询来更改列类型。
示例:
Dim strSql As String
strSql =" ALTER TABLE MyTable ALTER COLUMN MyField TEXT(20);"
DBEngine(0)(0)。执行strSql,dbFailOnError
我很难想象这会是一个好主意的场景
使用文本类型字段来保存日期/时间数据。这种方法可以释放大量问题,包括标准,排序,日期数学,无效条目,国际格式问题等等。
Dixie <二*** @ dogmail.com>在消息中写道
新闻:43 ******** @ duster.adelaide.on.net ...我如何以编程方式,取一些日期/时间字段当前数据库中的表格并将其类型更改为文本?
How can I programatically, take some Date/Time fields present in a table in
the current database and change their type to text?
dixie
解决方案
You can alter the column type by executing a DDL query.
Example:
Dim strSql As String
strSql = "ALTER TABLE MyTable ALTER COLUMN MyField TEXT(20);"
DBEngine(0)(0).Execute strSql, dbFailOnError
I''m having difficulty imagining a scenario where it would be a good idea to
use a Text type field to hold date/time data though. The approach would
unleash a plethoria of issues, with criteria, sorting, date math, invalid
entries, international format issues, and so on.
--
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.
"Dixie" <di***@dogmail.com> wrote in message
news:43********@duster.adelaide.on.net...How can I programatically, take some Date/Time fields present in a table
in the current database and change their type to text?
dixie
I''m probably going about it the wrong way, but I am using TransferText with
an export specification to produce a tab delimited text file I need and the
date/time fields have got 00:00:00 appended on the end of the date. There
is no time and I can''t afford this to go into the text file. I thought that
if I changed the table which is a temporary table made by a Maketable query
after it was produced so that the date/time fields were text fields the
problem would go away. I am sure there is a much more elegant solution
though.
dixie
"Allen Browne" <Al*********@SeeSig.Invalid> wrote in message
news:43**********************@per-qv1-newsreader-01.iinet.net.au...You can alter the column type by executing a DDL query.
Example:
Dim strSql As String
strSql = "ALTER TABLE MyTable ALTER COLUMN MyField TEXT(20);"
DBEngine(0)(0).Execute strSql, dbFailOnError
I''m having difficulty imagining a scenario where it would be a good idea
to use a Text type field to hold date/time data though. The approach would
unleash a plethoria of issues, with criteria, sorting, date math, invalid
entries, international format issues, and so on.
--
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.
"Dixie" <di***@dogmail.com> wrote in message
news:43********@duster.adelaide.on.net...How can I programatically, take some Date/Time fields present in a table
in the current database and change their type to text?
dixie
Easy solution: create a query that formats the date as you desire, and
export the query.
For example, you might type this into the Field row in query design:
Format([Date1], "Short Date")
replacing Date1 with the name of your date field.
--
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.
"Dixie" <di***@dogmail.com> wrote in message
news:43******@duster.adelaide.on.net...I''m probably going about it the wrong way, but I am using TransferText
with an export specification to produce a tab delimited text file I need
and the date/time fields have got 00:00:00 appended on the end of the
date. There is no time and I can''t afford this to go into the text file.
I thought that if I changed the table which is a temporary table made by a
Maketable query after it was produced so that the date/time fields were
text fields the problem would go away. I am sure there is a much more
elegant solution though.
dixie
"Allen Browne" <Al*********@SeeSig.Invalid> wrote in message
news:43**********************@per-qv1-newsreader-01.iinet.net.au...You can alter the column type by executing a DDL query.
Example:
Dim strSql As String
strSql = "ALTER TABLE MyTable ALTER COLUMN MyField TEXT(20);"
DBEngine(0)(0).Execute strSql, dbFailOnError
I''m having difficulty imagining a scenario where it would be a good idea
to use a Text type field to hold date/time data though. The approach
would unleash a plethoria of issues, with criteria, sorting, date math,
invalid entries, international format issues, and so on.
"Dixie" <di***@dogmail.com> wrote in message
news:43********@duster.adelaide.on.net...How can I programatically, take some Date/Time fields present in a table
in the current database and change their type to text?
这篇关于将表日期/时间字段更改为代码中的文本字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文