在C#中的SQL数据库中插入日期时间值 [英] insert datetime value in sql database with c#
本文介绍了在C#中的SQL数据库中插入日期时间值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要如何插入日期时间值到一个SQL数据库表,其中列的类型为datetime?
How do I insert a datetime value into a SQL database table where the type of the column is datetime?
推荐答案
的下面应该做的:
DateTime dateTimeVariable = //some DateTime value, e.g. DateTime.Now;
SqlCommand cmd = new SqlCommand("INSERT INTO <table> (<column>) VALUES (@value)", connection);
cmd.Parameters.AddWithValue("@value", dateTimeVariable);
cmd.ExecuteNonQuery();
这篇关于在C#中的SQL数据库中插入日期时间值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文