[英]Read Date from SQL Server
How do I read a date from SQL Server to a datetime
variable in C# ? 如何从SQL Server中读取日期到C#中的datetime
变量?
DateTime sDate = (read["notDate"]);
I get error 我得到错误
Cannot convert object to a system.datetime [are you missing a cast?] 无法将对象转换为system.datetime [您是否缺少演员表?]
Edit: the SQL Server uses a Date
datatype for this column. 编辑:SQL Server为此列使用Date
数据类型。
Then how will format the sDate
to UK format - I was looking at 然后如何将sDate
为UK格式-我在看
format("dd/MM/yyyy")
Using ASP.NET, C#, SQL Server Express. 使用ASP.NET,C#,SQL Server Express。
Thanks for your help. 谢谢你的帮助。
you need to cast it into a date.. this should do the job 您需要将其转换为日期。这应该可以完成工作
DateTime sDate = (DateTime)read["notDate"];
To then format it into a dd/MM/yyyy
you can do 然后将其格式化为dd/MM/yyyy
string formattedDate = sDate.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.