本文介绍了在数据库表字段中插入datetime的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我想获取当前时间/日期并将其插入数据库表但我收到错误。 DateTime DateTimeVariable = DateTime.Now.Date; SqlConnection con1 = new SqlConnection(Data Source = MZC-RWAHDAN \\ MYPROJECT2015; Persist Security Info = True; User ID = sa; Password = Fatima2010; Initial Catalog = Testing_database); SqlCommand command1 = new SqlCommand(insert into TrackIt(FullName,UserName,actiontype,actiondesc,actiontime)VALUES(@ param1,@ param2,@ param3,@ param4,@ param5,con1); con1.Open(); command1.Parameters.Add(new SqlParameter(@ param1,DataReader [FullName])); command1 .Parameters.Add(new SqlParameter(@ param2,DataReader [username])); command1.Parameters.Add(new SqlParameter(@ param3,Logged_IN)); command1.Parameters.Add(new SqlParameter(@ param4,以管理员身份登录到Admin_Page)); command1.Parameters.Add(new SqlParameter(@ param5,DateTimeVariable)); command1.ExecuteNonQuery(); 我得到了全名和先前查询的用户名数据,但其余的(3,4)我输入文本和最后一个一(5)我需要输入数据/时间进行跟踪。我收到错误: ' @ param5'。 请帮助, 谢谢。解决方案 Hi,I am trying to get the current time/date and insert it in database table but i get error.DateTime DateTimeVariable = DateTime.Now.Date; SqlConnection con1 = new SqlConnection("Data Source=MZC-RWAHDAN\\MYPROJECT2015;Persist Security Info=True;User ID=sa; Password=Fatima2010;Initial Catalog=Testing_database"); SqlCommand command1 = new SqlCommand("insert into TrackIt (FullName,UserName,actiontype,actiondesc,actiontime) VALUES(@param1,@param2,@param3,@param4,@param5", con1); con1.Open(); command1.Parameters.Add(new SqlParameter("@param1", DataReader["FullName"])); command1.Parameters.Add(new SqlParameter("@param2", DataReader["username"])); command1.Parameters.Add(new SqlParameter("@param3", "Logged_IN")); command1.Parameters.Add(new SqlParameter("@param4", "Logged in as Admin to Admin_Page")); command1.Parameters.Add(new SqlParameter("@param5", DateTimeVariable)); command1.ExecuteNonQuery();I am getting the full name and the username data from earlier query but the rest (3,4) i am entering text and the last one (5) i need to enter data/time for tracking. i get the error:Incorrect syntax near '@param5'.Please help,Thanks. 解决方案 这篇关于在数据库表字段中插入datetime的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-13 11:50