tags:

views:

19

answers:

1

Hi guys, I have a Datagrid in my app. This datagrid fetches some data from a MySQL DB. They are fetched from a List<> to be true, because I'm not able to fetch the data from a Dataset (and I don't know why).

Anyway, when I update a field in my app i want these changes to be reflected on the list and therefore on the table in my DB.

Any idea?

Also, it's a good option to save tables data on a List<> or it's better to save them on a DataSet/DataTable?

Thank you.

A: 

I'll answer your last question first. In general, you want to use DataSet/DataTable, because they have many methods and properties related to database functionality. A List<> may get you where you're going for now, but extending it in the future will be a nightmare.

I would focus on getting a DataSet properly filled from your Database (see: http://dev.mysql.com/usingmysql/dotnet/ if you don't know where to start), and then simply setting your DataGrid to use that DataSet as its DataSource. You can then use things like LINQ to SQL or Entity Framework to better model that DataSet in code. Assuming you have the proper ODBC drivers installed, it should be as simple as creating the correct Connection String and doing everything normally from there.

You can definitely do things the way you're doing now, but you will have to manually send any SQL update statements instead of relying on the automatic ways of doing it. But I would seriously consider reworking it to use proper .NET data objects.

drharris