PDA

Click to See Complete Forum and Search --> : Newbie ADO.Net Question


peteinman
Jun 13th, 2002, 06:03 AM
I've come from a client/server background using Non-MS development tools, and found the new ADO.Net concepts a little tricky to get my head round - disconnected recordsets etc.

I think I've got my head round how that works now and We're currently embarking on a development with .Net & SqlServer, and there's a couple of things I can't figure out.

1) Multi-User systems

How do I detect wether someone else has changed the data that I'm about to update.

How do you hande this using a DataGrid ?

The previous database product had a concept of RowID's, where if a row in the database had changed and I trie dto update it, it was possible to detect that and handle that in the code.

I haven't seen any discussions or articles on it, but if anyone could point me in the right direction I'd be grateful.

2) DataGrid

If I filled up a datagrid and wanted to set the cell color depending on a certain value, how could I do that ?

In my previous language ( None MS ) I'm used to picking up an event from a table as it fills up, and setting the colours of text at that point, but I can't see the same here at the moment.

Any help would be appreciated.


Pete

wolfofthenorth
Jun 13th, 2002, 09:36 PM
You can use Optimistic Concurency. If you use the DataAdapter Configuration Wizard you will have an option to build this into your update & delete statements.

If the data has been changed since the time you retrieved it, no update will occur on the changed records.

If you don't use the wizard, this is what it does behind the scenes, so you can do this manually.

UPDATE Table1 Set Col1 = @NewCol1Value,
Set Col2 = @NewCol2Value,
Set Col3 = @NewCol3Value
WHERE Col1 = @OldCol1Value AND
Col2 = @OldCol2Value AND
Col3 = @OldCol3Value

For more info look in the help under Optimistic Concurency. :)

peteinman
Jun 14th, 2002, 02:49 AM
So, if when you update and the data has changed, nothing gets updated, do you get an error you can handle in the application?

In my last company I was using a class to allow the user to re-edit the changed rows and I was hoping to do the same thing here.

Pete

wolfofthenorth
Jun 14th, 2002, 02:57 PM
If you set the DataAdapter.ContinueUpdateOnError = TRUE you can examine the e.Status property in the DataAdapter's Row_Updated Event for each row.

If it equals UpdateStatus.ErrorsOcurred you can react accordingly.

You can also leave DataAdapter.ContinueUpdateOnError = FALSE and the app will throw a concurency exception.

Hope this helps. :)

peteinman
Jun 21st, 2002, 10:43 AM
Thanks for your help, I've got things working now.
Pete