Skip navigation links

MySQL Forums :: Connector/NET and C#, Mono, .Net :: What changed with MySqlDbType.Datetime?


Advanced Search

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 system.data.dll

Additional information: Only DateTime objects can be serialized by MySqlDateTime

I hope this helps,

Thanks

Options: ReplyQuote


Subject Written By Posted
What changed with MySqlDbType.Datetime? Chris Cline 11/18/2004 08:20AM
Re: What changed with MySqlDbType.Datetime? Chris Cline 11/18/2004 08:32AM
Re: What changed with MySqlDbType.Datetime? Chris Cline 11/18/2004 10:37AM
Re: What changed with MySqlDbType.Datetime? Chris Cline 11/18/2004 02:43PM
Re: What changed with MySqlDbType.Datetime? Erica Albright 11/19/2004 06:51AM
Re: What changed with MySqlDbType.Datetime? David Dimmer 11/29/2004 10:14AM
Re: What changed with MySqlDbType.Datetime? David Dimmer 11/29/2004 10:17AM
Re: What changed with MySqlDbType.Datetime? David Dimmer 11/29/2004 11:04AM
Re: What changed with MySqlDbType.Datetime? Paul Hyman 11/29/2004 07:40PM
Re: What changed with MySqlDbType.Datetime? Chris Cline 11/30/2004 11:07AM
Any resolution for MySqlDbType.Datetime? Thomas Hayes 12/03/2004 04:42PM
Re: Any resolution for MySqlDbType.Datetime? Umberto Ballestrazzi 12/09/2004 02:43PM


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.