I am using MySQL .NET Connector for C#. It has been working perfectly
until recently. I have a field in my MySQL Table storing data of type
TIME. Identically in my .NET application, I have a dataset with a table
and a field of type TIMESPAN. My C# application calculates a time
difference and stores it in the MySQL database. The time difference may
be of negative value. The negative values are being stored correctly in
the database. The problem occurs when I use a TableAdapter in C# to fill
my .NET data table in code, hence reading back the values from MySQL
into C#. Values less than an hour are always loaded as positive value,
no mather if it is negative or positive in the MySQL table. Values
stored in the MySQL table which are more than one hour in value are
being loaded with correct sign.
Even though I use a scalar query to load a single TIME value into a
variable the query is not able to keep the sign of negative time values
(values less than one hour).
CODE:
MySqlConnection myConn = new MySqlConnection(DatabaseConnectionString);
MySqlCommand myCommand = new MySqlCommand("MY QUERY", myConn);
MySqlDataAdapter myAdapter = new MySqlDataAdapter();
System.Data.DataTable myData = new DataTable();
myConn.Open();
myAdapter.SelectCommand = myCommand;
myAdapter.Fill(myData); //Load data into table
CODE END
I am not sure if it matters, but in my connection string I have set
"Allow Zero Datetime=True" to handle possible DateTime issues.
Any idea what causes the wrong sign for values less than one hour when
reading data from MySQL into C# Data Table?
Example: stored value in MySQL table is -02:45:00 read value in C#
is -02:45:00
Example: stored value in MySQL table is -00:30:00 read value in C# is
00:30:00 (sign lost!)
until recently. I have a field in my MySQL Table storing data of type
TIME. Identically in my .NET application, I have a dataset with a table
and a field of type TIMESPAN. My C# application calculates a time
difference and stores it in the MySQL database. The time difference may
be of negative value. The negative values are being stored correctly in
the database. The problem occurs when I use a TableAdapter in C# to fill
my .NET data table in code, hence reading back the values from MySQL
into C#. Values less than an hour are always loaded as positive value,
no mather if it is negative or positive in the MySQL table. Values
stored in the MySQL table which are more than one hour in value are
being loaded with correct sign.
Even though I use a scalar query to load a single TIME value into a
variable the query is not able to keep the sign of negative time values
(values less than one hour).
CODE:
MySqlConnection myConn = new MySqlConnection(DatabaseConnectionString);
MySqlCommand myCommand = new MySqlCommand("MY QUERY", myConn);
MySqlDataAdapter myAdapter = new MySqlDataAdapter();
System.Data.DataTable myData = new DataTable();
myConn.Open();
myAdapter.SelectCommand = myCommand;
myAdapter.Fill(myData); //Load data into table
CODE END
I am not sure if it matters, but in my connection string I have set
"Allow Zero Datetime=True" to handle possible DateTime issues.
Any idea what causes the wrong sign for values less than one hour when
reading data from MySQL into C# Data Table?
Example: stored value in MySQL table is -02:45:00 read value in C#
is -02:45:00
Example: stored value in MySQL table is -00:30:00 read value in C# is
00:30:00 (sign lost!)