Home > Enterprise >  Trying to map a Date to object using mysqlconnector in C#
Trying to map a Date to object using mysqlconnector in C#

Time:08-24

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 enter image description here

CodePudding user response:

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

  • Related