Re: What changed with MySqlDbType.Datetime?
Posted by: Chris Cline
Date: November 18, 2004 10:37AM

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

Additional information: Only DateTime objects can be serialized by MySqlDateTime

I hope this helps,


Options: ReplyQuote

Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.