Description:
When a row in a DataTable is modified that contains a column of type Float, a concurrency exception is always thrown whether the float value has been changed or not. The repeat section contains the code to reproduce the error including the SQL to generate the table in question.
How to repeat:
using ByteFX.Data.MySqlClient;
using System;
using System.Data;
namespace DBTester
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
MySqlConnection clConnection = new MySqlConnection( "Data Source=localhost;User ID=root;Database=dbtest" );
MySqlCommand clCommand = new MySqlCommand();
MySqlDataAdapter clAdapter = new MySqlDataAdapter();
MySqlCommandBuilder clCommandBuilder = new MySqlCommandBuilder( clAdapter );
string sCommand = "SELECT * FROM testtable";
DataTable dtDataTable = new DataTable();
try
{
clCommand.Connection = clConnection;
// Get data from the database.
clConnection.Open();
clCommand.CommandText = sCommand;
clAdapter.SelectCommand = clCommand;
clAdapter.Fill(dtDataTable);
// Change the database record
dtDataTable.Rows[0]["name"] = "John";
clConnection.Close();
// Reset commands and adapter for new update.
clConnection = new MySqlConnection( "Data Source=localhost;User ID=root;Database=dbtest" );
clConnection.Open();
clCommand = new MySqlCommand();
clAdapter = new MySqlDataAdapter();
clCommandBuilder = new MySqlCommandBuilder( clAdapter );
clCommand.Connection = clConnection;
clCommand.CommandText = sCommand;
clAdapter.SelectCommand = clCommand;
clAdapter.Update( dtDataTable );
clConnection.Close();
Console.WriteLine("Data updated successfully.");
}
catch( Exception ex )
{
Console.WriteLine(ex.Message);
clConnection.Close();
}
Console.ReadLine();
}
}
}
/*
create table testtable
(
id int unsigned auto_increment not null,
name varchar(255) not null,
salary float not null,
primary key( id )
);
insert into testtable values( null, "Dave", 9.55 );
*/
Suggested fix:
The DataAdapter needs to recognize when the float value has actually changed from the last read. This could be some kind of rounding issue with floating point comparisons.