如何使用当前时间将值保存到数据库。 [英] How to save values to Database with current Time.
本文介绍了如何使用当前时间将值保存到数据库。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在将值保存到数据库,但我无法使用当前时间保存它们。
我在数据库中创建了一个名为Time的colume,但不知道如何节省时间。
SqlConnection sqlconn = new SqlConnection( 数据源= AAN-PC;初始目录= latestsensordata;集成安全性=真);
SqlDataAdapter sa = new SqlDataAdapter();
string query = 插入Table_1( SensorValue,Time)值( + hexValue + );
sa.InsertCommand = new SqlCommand(query,sqlconn);
解决方案
您好,
为了保持一致性,我认为您需要服务器时间而不是客户端PC时间。
您需要做的就是在桌面上设置默认为Getdate()的时间。
HI,
这里只传递会话值。
string query =插入Table_1(SensorValue,Time)值(+ hexValue +,+ DateTime.Now.ToString(HH:MM:ss)+);
谢谢
您好,
为了保持一致性,我认为您需要服务器时间而不是客户端PC时间。
您需要做的就是在桌面上设置默认为Getdate()的时间。
这样你就可以了不要在插入时传递任何值。
I am saving values to a database but I am not able to save them with current Time.
I have created a colume with name Time in database, but dont know how to save time.
SqlConnection sqlconn = new SqlConnection("Data Source=AAN-PC;Initial Catalog=latestsensordata;Integrated Security=True");
SqlDataAdapter sa = new SqlDataAdapter();
string query = "insert into Table_1(SensorValue,Time) values(" +hexValue+")";
sa.InsertCommand = new SqlCommand(query, sqlconn);
解决方案
Hi,
For consistency I would assume you require the server time and not the client pc time.
All you need to do is set the Time on your table with a default of Getdate().
HI,
Here you are passing only session values.
string query = "insert into Table_1(SensorValue,Time) values(" +hexValue+ "," +DateTime.Now.ToString("HH:MM:ss")+")";
Thanks
Hi,
For consistency I would assume you require the server time and not the client pc time.
All you need to do is set the Time on your table with a default of Getdate().
In this way you don''t pass any value on insert.
这篇关于如何使用当前时间将值保存到数据库。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文