简体   繁体   中英

Trying to map a Date to object using mysqlconnector in C#

I am trying to read information from my DAL and am wondering what built in types am I suppose to use in C# to extract the DATE Data Type in MySql to retrieve information. Am I suppose to use DateTime and convert the DateTime to Date or is there a way in C# where we can retrieve specified information when calling upon it. I have an image of the DS at the bottom

DATA_ACCESS_LAYER CODE SNIPIT

using MySqlConnector;
...
...
private IObject ReadInformation(MySqlDataReader reader, IObject object)
{
    try 
    {
        while (reader.Read)
        {
            ((Object)object).Birthday = reader.getDateOnly("Birthday"); 
            // ^ My Current issue of questioning what Data type 
            // do I have to use under the reader and do I have to change the 
            // IObject.Birthday datatype.
        }
    }
    // catch code
}

Object Interface

class IObject 
{
    string FirstName;
    ...
    DateOnly Birthday;
}

Object Class

class Object : IObject
{
    public string FirstName { get; set; } = string.Empty;
    ... 
    public DateOnly Birthday { get; set; }
}

Image of the MySQL Database Field 在此处输入图像描述

The Answer was my initial assumption that I must change the datatype from DateOnly -> DateTime. -- Answered by Flydog57

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM