将日期插入SQL Server [英] Insert Date into SQL Server

查看:89
本文介绍了将日期插入SQL Server的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将数据输入表格,

但是我的sql语句出了问题。


它就像是那个:


现在变暗如String = DateTime.Now.ToString

INSERT INTO table(date)VALUES(now)


我知道还有ToShortDateString但是它无论如何都没有改变我的字符串




Atm SQL String中的日期看起来喜欢:20.5.2004 09:00:00

它应该是这样的:20-May-2004 09:00


任何想法怎么样完成???


Thx,


Stefan

Hi, I am trying to enter data into a table,
but I got problems with my sql statement.

It''s something like that:

Dim now As String = DateTime.Now.ToString
INSERT INTO table (date) VALUES(now)

I know there is also ToShortDateString but it didn''t change my String in
anyway.

Atm the date in the SQL String looks like: 20.5.2004 09:00:00
and it should like like: 20-May-2004 09:00

Any idea how that is to be done???

Thx,

Stefan

推荐答案

您好


您需要转换为YYYY-MM-DD HH:MM:SS才能将
插入到ms sql server 2000中。


亲切的问候

Jorge
Hi

You need to convert to YYYY-MM-DD HH:MM:SS before you can
insert into ms sql server 2000.

Kind Regards
Jorge
-----原帖-----
我正在尝试将数据输入表格,
但是我的sql语句出了问题。

就是这样的:

现在变暗如String = DateTime.Now.ToString
INSERT INTO table(date)VALUES(now)

我知道还有ToShortDateString,但它并没有
改变我的字符串。

Atm SQL字符串中的日期如下:20.5.2004
09: 00:00它应该像:2004年5月20日09:00

任何想法怎么做???

Thx,

Stefan

-----Original Message-----
Hi, I am trying to enter data into a table,
but I got problems with my sql statement.

It''s something like that:

Dim now As String = DateTime.Now.ToString
INSERT INTO table (date) VALUES(now)

I know there is also ToShortDateString but it didn''t change my String inanyway.

Atm the date in the SQL String looks like: 20.5.2004 09:00:00and it should like like: 20-May-2004 09:00

Any idea how that is to be done???

Thx,

Stefan
.



*" Stefan Richter" < SP ** @ spammenot.com> scripsit:
* "Stefan Richter" <sp**@spammenot.com> scripsit:
我正在尝试将数据输入表格,
但是我的sql语句出了问题。

就是这样的:

现在变暗如String = DateTime.Now.ToString
INSERT INTO表(日期)VALUES(现在)

我知道还有ToShortDateString但它没有无论如何都不要改变我的字符串。

Atm SQL字符串中的日期看起来像:20.5.2004 09:00:00
它应该像:20 -May-2004 09:00
Hi, I am trying to enter data into a table,
but I got problems with my sql statement.

It''s something like that:

Dim now As String = DateTime.Now.ToString
INSERT INTO table (date) VALUES(now)

I know there is also ToShortDateString but it didn''t change my String in
anyway.

Atm the date in the SQL String looks like: 20.5.2004 09:00:00
and it should like like: 20-May-2004 09:00




使用''InsertCommand''+参数代替:


使用带参数的参数DataAdapter

< URL:http://msdn.microsoft.com/library/en-us/cpguide/html/cpconusingparameterswithdataadapters.asp>


- -

Herfried K. Wagner [MVP]

< URL:http://dotnet.mvps.org/>



Use an ''InsertCommand'' + parameters instead:

Using Parameters with a DataAdapter
<URL:http://msdn.microsoft.com/library/en-us/cpguide/html/cpconusingparameterswithdataadapters.asp>

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>


是的,这就是我想要做的事情!


我发现你可以使用这种格式我在toString

方法的括号中,


但它从不接受DD和HH之间的空格!


DateTime.Now.ToString(" YYYY-MM-DD HH:MM")

Stefan
Yeah, that is just what I am trying to do!

I found out that you can use this format in the brackets of the toString
method,

but it never accepts the space between the DD and HH!

DateTime.Now.ToString("YYYY-MM-DD HH:MM")
Stefan


这篇关于将日期插入SQL Server的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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