Results 1 to 5 of 5

Thread: Newbie ADO.Net Question

  1. #1
    peteinman
    Guest

    Newbie ADO.Net Question

    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

  2. #2
    Addicted Member wolfofthenorth's Avatar
    Join Date
    Jan 2001
    Location
    Tatooine
    Posts
    169
    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.
    That which does not kill us, only makes us stronger.

  3. #3
    peteinman
    Guest
    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

  4. #4
    Addicted Member wolfofthenorth's Avatar
    Join Date
    Jan 2001
    Location
    Tatooine
    Posts
    169
    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.
    That which does not kill us, only makes us stronger.

  5. #5
    peteinman
    Guest
    Thanks for your help, I've got things working now.
    Pete

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width