Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用VB.Net将DateTime插入postgreSql数据库_Vb.net_Postgresql - Fatal编程技术网

使用VB.Net将DateTime插入postgreSql数据库

使用VB.Net将DateTime插入postgreSql数据库,vb.net,postgresql,Vb.net,Postgresql,我正在尝试使用VB.Net插入日期时间字段: 这是我的代码: Command = New NpgsqlCommand("insert into test_base(create_date) values( '" + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss.fff").ToString + "')", conn) 但它将日期插入到12小时格式,我需要将日期插入到24小时格式。尝试将“hh”更改为“hh”,如下所示: Command = New Npg

我正在尝试使用VB.Net插入日期时间字段:

这是我的代码:

Command = New NpgsqlCommand("insert into test_base(create_date) values( '" + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss.fff").ToString + "')", conn)
但它将日期插入到12小时格式,我需要将日期插入到24小时格式。

尝试将“hh”更改为“hh”,如下所示:

Command = New NpgsqlCommand("insert into test_base(create_date) values( '" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff").ToString + "')", conn)
此链接显示了几种操作格式的方法:


我使用currentlty pg函数来设置时间戳:

 Insert into foo(t) VALUES(to_Timestamp('17/05/15 14:38:55','dd/mm/yy HH24:mi:ss'))
不可能出错。
如果必须插入更多行,请考虑参数化查询。

请阅读有关参数化查询的内容。顺便说一下,如果你将日期存储为字符串,你将不得不面对很多问题。日期应该存储为DatesHanks为了得到建议,我只需要将日期转换为24小时。DateTime类型是一个值,它们没有格式-格式是日期如何向人类显示的。如果DB列是日期类型,只需传递DateTime值Thank@Reisclef,这正是我需要的