如何从MySQL数据库C#DateTime对象的日期? [英] How to get a date from MySql database to C# DateTime object?
问题描述
我有包含日期某一个领域一个MySQL数据库。
I have a MySQL database with a certain field that contains a date.
我怎样才能将其转换为C#的DateTime
对象?
How can I convert it to a C# DateTime
object?
我如何转换成一个C#的DateTime
对象,这样我就可以把它插入到数据库?
And how do I convert a C# DateTime
object so I can insert it to the database?
推荐答案
您将需要的的MySQL Connector用于.NET 的,如果你不已经拥有了它,为了得到你的C#应用程序谈论到MySQL。
You'll need the MySQL Connector for .NET, if you don't already have it, in order to get your C# application talking to MySQL.
然后,你就可以拿到日期列出您的数据库,并为datetime对象的标准方式,使用的的MySqlConnection ,的的MySqlCommand ,的 MySqlDataReader将等。
Then you'll be able to get the date columns out of your database and into DateTime objects in the standard way, using MySqlConnection, MySqlCommand, MySqlDataReader etc.
有MySQL的日期/时间和.NET日期时间之间转换时有一些潜在的陷阱,但有一个 MySQL文档一中有用的部分>对如何处理这些问题的建议。
There are a few potential gotchas when converting between MySQL dates/times and .NET DateTimes, but there's a useful section in the MySQL documentation with advice on how to handle the issues.
这篇关于如何从MySQL数据库C#DateTime对象的日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!