Re: What changed with MySqlDbType.Datetime?
I did some more testing so I created a test database and one table. I then created a simple MySqlDataAdapter object as follows:
DataTable dt = new DataTable("customer");
MySqlConnection mCon = new MySqlConnection( myConnection );
mAdapter = new MySqlDataAdapter();
MySqlCommand mSelect = new MySqlCommand("SELECT * FROM customer", mCon );
mSelect.Parameters.Add("id", MySqlDbType.Int32,11,"id");
mSelect.Parameters.Add("display_name", MySqlDbType.VarChar, 100, "display_name" );
mSelect.Parameters.Add("created", MySqlDbType.Datetime, 8, "created" );
MySqlCommand mInsert = new MySqlCommand("INSERT INTO customer ( display_name, created ) VALUES( ?display_name, ?created ); SELECT LAST_INSERT_ID() AS id", mCon );
mInsert.Parameters.Add("id", MySqlDbType.Int32,11,"id");
mInsert.Parameters.Add("display_name", MySqlDbType.VarChar, 100, "display_name" );
mInsert.Parameters.Add("created", MySqlDbType.Datetime, 8, "created" );
MySqlCommand mUpdate = new MySqlCommand("UPDATE customer SET display_name=?display_name, created=?created WHERE id=?id", mCon );
mUpdate.Parameters.Add("id", MySqlDbType.Int32,11,"id");
mUpdate.Parameters.Add("display_name", MySqlDbType.VarChar, 100, "display_name" );
mUpdate.Parameters.Add("created", MySqlDbType.Datetime, 8, "created" );
MySqlCommand mDelete = new MySqlCommand("DELETE FROM customer WHERE id=?id", mCon );
mDelete.Parameters.Add("id", MySqlDbType.Int32,11,"id");
mDelete.Parameters.Add("display_name", MySqlDbType.VarChar, 100, "display_name" );
mDelete.Parameters.Add("created", MySqlDbType.Datetime, 8, "created" );
mAdapter.SelectCommand = mSelect;
mAdapter.InsertCommand = mInsert;
mAdapter.UpdateCommand = mUpdate;
mAdapter.DeleteCommand = mDelete;
mAdapter.Fill( dt );
Then I bind it to a DataGrid I put on a form as follows:
this.dataGrid1.DataSource = dt;
Now when I enter data into the datagrid and try and update the Adapter I get the following error:
An unhandled exception of type 'MySql.Data.MySqlClient.MySqlException' occurred in system.data.dll
Additional information: Only DateTime objects can be serialized by MySqlDateTime
I hope this helps,
Thanks