Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. ADO.NET - Best way to use the mighty SELECT

ADO.NET - Best way to use the mighty SELECT

Scheduled Pinned Locked Moved Database
csharpdatabasehelpquestionannouncement
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    BinaryHead
    wrote on last edited by
    #1

    I´ve used the DataReader, DataSet, ExecuteScalar, etc. However Im not sure what of these is the best solution for the following problem: I want to use a simple SELECT and loop through the data, and update some of the data but make sure no two persons can UPDATE some of the selected transactions at the same time. I could loop through the data with ExecuteScalar or DataReader, but would it allow two users to update the same data at the same time? (without locking the database) Thanks in advance :) BinaryHead

    C D 2 Replies Last reply
    0
    • B BinaryHead

      I´ve used the DataReader, DataSet, ExecuteScalar, etc. However Im not sure what of these is the best solution for the following problem: I want to use a simple SELECT and loop through the data, and update some of the data but make sure no two persons can UPDATE some of the selected transactions at the same time. I could loop through the data with ExecuteScalar or DataReader, but would it allow two users to update the same data at the same time? (without locking the database) Thanks in advance :) BinaryHead

      C Offline
      C Offline
      Colin Angus Mackay
      wrote on last edited by
      #2

      BinaryHead wrote: make sure no two persons can UPDATE some of the selected transactions at the same time. transactions? You mean rows, surely. Personally I'd create a stored procedure for this sort of thing (if possible) which has the added advantage of a single round trip to the database. Anyway, you can create a transaction and run multiple commands in the same transaction and then commit it. There is an example here on MSDN[^]


      My: Blog | Photos WDevs.com - Open Source Code Hosting, Blogs, FTP, Mail and More

      1 Reply Last reply
      0
      • B BinaryHead

        I´ve used the DataReader, DataSet, ExecuteScalar, etc. However Im not sure what of these is the best solution for the following problem: I want to use a simple SELECT and loop through the data, and update some of the data but make sure no two persons can UPDATE some of the selected transactions at the same time. I could loop through the data with ExecuteScalar or DataReader, but would it allow two users to update the same data at the same time? (without locking the database) Thanks in advance :) BinaryHead

        D Offline
        D Offline
        david cohoon
        wrote on last edited by
        #3

        There are many different ways of ensuring that the rows are not modified while you are accessing them. But, let me ask you first - is it feasable that the data in the db can be altered by means other than your application? Ensuring optimitic locking inside your application only works if everyone is using your application to access the data. If others might have access to the data outside of your application, you'll most likely want to push all your updates into a transaction and set the isolation level accordingingly.

        B 1 Reply Last reply
        0
        • D david cohoon

          There are many different ways of ensuring that the rows are not modified while you are accessing them. But, let me ask you first - is it feasable that the data in the db can be altered by means other than your application? Ensuring optimitic locking inside your application only works if everyone is using your application to access the data. If others might have access to the data outside of your application, you'll most likely want to push all your updates into a transaction and set the isolation level accordingingly.

          B Offline
          B Offline
          BinaryHead
          wrote on last edited by
          #4

          There could be many people accessing the same data at the same time using this application (many instances/copies of my program) Im trying to build (but not accessing the data with some third party application). Im just scared of one thing: - If two different programs, A and B, are running at the same time(both using the same database) and A requests some rows with the DataReader (f.ex. SELECT... where some Boolean == false) and at the same time B updates some of the SAME rows (UPDATE...where ..SET Boolean == true). Is the DataREader in A smart enough to SELECT some rows, and then while looping through them, figure out that one of the rows has been changed (Boolean == true) so it should skip it in the loop? (or are the rows that the DataReader returns just copied into memory and then looped blindly like the DataSet with Adapter.Fill() / Adapter.Update()? ).

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups