The problem that MySQL is being applied in nhib.pdf is about a blank date

Source: Internet
Author: User
Unable to convert MySQL date/time value to system. datetime
I believe many people will see this problem. In MySQL databases, such dates are ". Set allow zero datetime = true. This type of date returns a mysqldatetime type in connector-net-5.1.4. The value is naturally 0000-0-0, nullables. when nhibde obtains this value, it tries to convert it to public override object get (idatareader RS, int index)
{
Return new nullabledatetime (convert. todatetime (RS [Index]); // Rs [Index] is an object of mysqldatetime
}

The above error will be thrown.

If "allow zero datetime = true" is not set in the connection string, the above error int Index = Rs. getordinal (name) will be thrown when determining whether it is dbnull );

If (Rs. isdbnull (INDEX ))
{
If (isdebugenabled)
{
Log. debug ("returning null as column:" + name );
}
// Todo: Add a method to nullabletype. getnullvalue-if we want
// Use "magic" numbers to indicate null values
Return NULL;
}
Else
{
Object val = NULL;
Try
{
Val = get (RS, index );
}.
}

I thought that I could find a solution by downloading the source code of connector-net. I didn't expect that a project could not be opened, and the compiled dll could not be added to GAC, so I had to go back and change nullables. nhib.pdf. nullabledatetimetypepublic override object get (idatareader RS, int index)
{
// Return New nullabledatetime (convert. todatetime (RS [Index]);
// Kevin modify
Object OBJ = Rs [Index];
String strname = obj. GetType (). tostring ();
If (strname = "mysql. Data. types. mysqldatetime ")
{
String strval = obj. tostring ();
If (strval. startswith ("0000-0-0 "))
Return NULL;
Else
Return new nullabledatetime (convert. todatetime (strval ));
}
Else
{
Return new nullabledatetime (convert. todatetime (RS [Index]);
}
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.