如何获取日期从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
object?
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连接器.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.
然后,您可以使用 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 DateTimes,但有一个有用的部分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屋!