Jump to content

DataGridView objects and MySQL databases

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1
mholt

mholt

    Newbie

  • Members
  • PipPip
  • 27 posts
Hi,

I'm writing a MySQL database manager in C# - Visual Studio 2008. Consider this scenario: have a DataGridView object showing the data in a table from a certain database the user connected to.

The user changes the value in a field. This table may or may not contain a primary key. This change is expected to be saved into the database table.

I obviously need to run an UPDATE query (which I know how to do), but what I don't know how to do is figure out what the selectors for that query should be. I.e: what data do I need to gather to make sure that the specific field the user changes is the one that is updated, and nothing else?

Keep in mind that the rows could be out of order in the DataGridView because the user can sort them any way they want.

Thanks for any aid.

#2
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts
You could try binding the datagridview to the database. This will automatically update them, with a lot less work.
How about loading the data into a DataSet, then making the change to one of its properties, before updating the data back again? That way, only the specified change is updated. There's no harm in reupdating the same value in the field, eh?

I tend to steer clear from databases and store everthing in XML Files, as they're so much easier to use. Just use some objects from the System.Xml namespace, and voila!

But that's just me being lazy. Xav
Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums