BindingSource based on object::typeid (how to fill data from DB)

P

pmz

Dear Friends,

1. I've created an object named i.e. Cup_Event with few properties
(getters & setters).
2. I've created DataGridView, with data source created from binding
source based on object mentioned above.

this->cupEventBindingSource->DataSource =
Cup::Data::Cup_Event::typeid;

The problem is, I'm not totally sure how do I fill my DGV with data?
I've done it before via BindingSource > DataSet < DbDataAdapter <
Fill, etc. and worked perfectly. Now I've tried something else, and
I'm stuck in the filling moment.

For sure I need to fetch data - the question is, shall I use
DataAdapter (MySqlDataAdapter/SqlDataAdapter) or DataReader and
building list of objects (Cup_Event)? Or maybe I use object for
building the DGV columns (VS designer) and further I may use the
DataSet-filling-method?

Thank you for any help,

Przemek M. Zawada
 
P

pmz

Okay, I've tried a bit risky, anyway with success:

this->cupEventBindingSource->DataSource =
Cup::Data::Cup_Event::typeid;
Cup::Data::Cup_Event^ cupEvent = gcnew Cup::Data::Cup_Event();
MySql::Data::MySqlClient::MySqlCommand^ cmd = gcnew
MySql::Data::MySqlClient::MySqlCommand("SELECT * FROM Cup_Event",
cupEvent->DatabaseConnection);
MySql::Data::MySqlClient::MySqlDataAdapter^ adapter = gcnew
MySql::Data::MySqlClient::MySqlDataAdapter(cmd);
DataSet^ ds = gcnew DataSet();
adapter->Fill(ds, "Cup_Event");
this->cupEventBindingSource->DataSource = ds->Tables["Cup_Event"];

Worked PERFECTLY, still, my question is - am I doing everything ok?

All the best,
Przemek M. Zawada
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top