如何使用C#.net在SQL Server中存储日期 [英] how to store the date in sql server using for c#.net
本文介绍了如何使用C#.net在SQL Server中存储日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用c#.net在SQL Server中存储日期.
请发送代码
how to store the date in sql server using for c#.net.
please send the code
推荐答案
要存储日期,您可以使用^ ]数据类型.要将当前日期设置为SQL Server中的列,请使用 GETDATE() [ SqlCommand [ ^ ]以及与 SqlParameter [
To store a date you can use date[^] data type. To set current date into the column in SQL Server use GETDATE()[^]
If you want to pass a date from client side, use SqlCommand[^] along with SqlParameter[^]
^ ]
如果您的日期格式为dd/MM/yyyy,则您需要将其转换为sql格式
使用以下代码
Hi,
if Your date Format is dd/MM/yyyy then u need to convert it in sql Format
using following Code
IFormatProvider provider = new System.Globalization.CultureInfo("en-CA", true);
string strDate = DateTime.Parse(txtDate.Text.Trim(), provider, System.Globalization.DateTimeStyles.NoCurrentDateDefault).Date.ToString();
然后你可以将其传递给Db ok
祝你好运
then u can pass it to Db ok
Best Luck
这篇关于如何使用C#.net在SQL Server中存储日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文