使用C#将当前日期和时间插入sql数据库 [英] Insert current date and time into the sql database using C#

查看:863
本文介绍了使用C#将当前日期和时间插入sql数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经输入了查询.但没有查询日期和时间.

I have already type a query. but in that query date and time were not taken. 

 String name = (buff.ToString());
                sql_con.Open();
              

                try
                {


                    string sql = "INSERT INTO ActiveWindow(empId,time,winName) VALUES('" + userId+"','" + DateTime.Now + "','" + name + "')";

                    SQLiteCommand command = new SQLiteCommand(sql, sql_con);
                    command.ExecuteNonQuery();



                }
                catch (Exception ex)
                {

                }

                sql_con.Close();

推荐答案

  查询没有问题,请检查时间"字段的数据类型.创建表时输入列".列的数据类型可能与存储DateTime不兼容.

   There is no problem with the query, please check with the data type of the "time" column while you have created the table. The data type of the column may not be compatible to store DateTime.

谢谢


这篇关于使用C#将当前日期和时间插入sql数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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