Connector/Net Programming
1917
<ExceptionInterceptors>
<add name="myE"
type="ExceptionStackTraceTest.MyExceptionInterceptor,ExceptionStackTraceTest" />
</ExceptionInterceptors>
</MySQL>
Once you have done that, your connection strings can look like these:
MySqlConnection c1 = new MySqlConnection(@"server=localhost;pooling=false;
commandinterceptors=myC");
MySqlConnection c2 = new MySqlConnection(@"server=localhost;pooling=false;
exceptioninterceptors=myE");
20.2.5.12. Handling Date and Time Information in Connector/Net
MySQL and the .NET languages handle date and time information differently, with MySQL allowing
dates that cannot be represented by a .NET data type, such as '
0000-00-00 00:00:00
'. These
differences can cause problems if not properly handled.
The following sections demonstrate how to properly handle date and time information when using
Connector/Net.
20.2.5.12.1. Fractional Seconds
Connector/Net 6.5 and higher support the fractional seconds feature introduced in MySQL 5.6.4.
Fractional seconds could always be specified in a date literal or passed back and forth as parameters
and return values, but the fractional part was always stripped off when stored in a table column. In
MySQL 5.6.4 and higher, the fractional part is now preserved in data stored and retrieved through SQL.
For fractional second handling in MySQL 5.6.4 and higher, see
Fractional Seconds in Time Values
. For
the behavior of fractional seconds prior to MySQL 5.6.4, see
Fractional Seconds in Time Values
.
To use the more precise date and time types, specify a value from 1 to 6 when creating the table
column, for example
TIME(3)
or
DATETIME(6)
, representing the number of digits of precision after
the decimal point. Specifying a precision of 0 leaves the fractional part out entirely. In your C# or
Visual Basic code, refer to the
Millisecond
member to retrieve the fractional second value from the
MySqlDateTime
object returned by the
GetMySqlDateTime
function. The
DateTime
object returned
by the
GetDateTime
function also contains the fractional value, but only the first 3 digits.
For related code examples, see the following blog post:
https://blogs.oracle.com/MySqlOnWindows/
entry/milliseconds_value_support_on_datetime
20.2.5.12.2. Problems when Using Invalid Dates
The differences in date handling can cause problems for developers who use invalid dates. Invalid
MySQL dates cannot be loaded into native .NET
DateTime
objects, including
NULL
dates.
Because of this issue, .NET
DataSet
objects cannot be populated by the
Fill
method of the
MySqlDataAdapter
class as invalid dates will cause a
System.ArgumentOutOfRangeException
exception to occur.
20.2.5.12.3. Restricting Invalid Dates
The best solution to the date problem is to restrict users from entering invalid dates. This can be done
on either the client or the server side.
Restricting invalid dates on the client side is as simple as always using the .NET
DateTime
class
to handle dates. The
DateTime
class will only allow valid dates, ensuring that the values in your
database are also valid. The disadvantage of this is that it is not useful in a mixed environment
where .NET and non .NET code are used to manipulate the database, as each application must
perform its own date validation.
Содержание 5.0
Страница 1: ...MySQL 5 0 Reference Manual ...
Страница 18: ...xviii ...
Страница 60: ...40 ...
Страница 396: ...376 ...
Страница 578: ...558 ...
Страница 636: ...616 ...
Страница 844: ...824 ...
Страница 1234: ...1214 ...
Страница 1426: ...MySQL Proxy Scripting 1406 The following diagram shows an overview of the classes exposed by MySQL Proxy ...
Страница 1427: ...MySQL Proxy Scripting 1407 ...
Страница 1734: ...1714 ...
Страница 1752: ...1732 ...
Страница 1783: ...Configuring Connector ODBC 1763 ...
Страница 1793: ...Connector ODBC Examples 1773 ...
Страница 1839: ...Connector Net Installation 1819 2 You must choose the type of installation to perform ...
Страница 1842: ...Connector Net Installation 1822 5 Once the installation has been completed click Finish to exit the installer ...
Страница 1864: ...Connector Net Visual Studio Integration 1844 Figure 20 24 Debug Stepping Figure 20 25 Function Stepping 1 of 2 ...
Страница 2850: ...2830 ...
Страница 2854: ...2834 ...
Страница 2928: ...2908 ...
Страница 3000: ...2980 ...
Страница 3122: ...3102 ...
Страница 3126: ...3106 ...
Страница 3174: ...3154 ...
Страница 3232: ...3212 ...