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. Fill DataSet with nothing

Fill DataSet with nothing

Scheduled Pinned Locked Moved Database
csharpdatabasequestion
5 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.
  • S Offline
    S Offline
    SebbaP
    wrote on last edited by
    #1

    Hi, I am reviewing existing code and stumbled across something that, to me - and I'm new to ADO.NET, seems very awkward. A DataSet is filled using a OleDbDataAdapter. The weird thing is that the command does not affect any records at all, intentionally. It looks something like "SELECT ... WHERE 0 = 1". The comment describing the method containing this code says "Retrieve an empty dataset that contains the database structure". DataSet Quick Whatch reports the dataset to be empty after the fill. Does this SELECT statement really do any good? :confused: Thanks for comments, ideas or advise!

    C S 2 Replies Last reply
    0
    • S SebbaP

      Hi, I am reviewing existing code and stumbled across something that, to me - and I'm new to ADO.NET, seems very awkward. A DataSet is filled using a OleDbDataAdapter. The weird thing is that the command does not affect any records at all, intentionally. It looks something like "SELECT ... WHERE 0 = 1". The comment describing the method containing this code says "Retrieve an empty dataset that contains the database structure". DataSet Quick Whatch reports the dataset to be empty after the fill. Does this SELECT statement really do any good? :confused: Thanks for comments, ideas or advise!

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

      I don't use datasets because they tend to encourage the data layer to get too close to the presentation layer (not good design). The SELECT statement returns, as you've already noticed, an empty set. But that isn't to say that nothing at all was returned. I'm guessing that the empty DataSet is subsequently used to look at the data schema without actually needing to get any data. Obviously, it would be wasteful to get data that isn't going to be used.


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

      1 Reply Last reply
      0
      • S SebbaP

        Hi, I am reviewing existing code and stumbled across something that, to me - and I'm new to ADO.NET, seems very awkward. A DataSet is filled using a OleDbDataAdapter. The weird thing is that the command does not affect any records at all, intentionally. It looks something like "SELECT ... WHERE 0 = 1". The comment describing the method containing this code says "Retrieve an empty dataset that contains the database structure". DataSet Quick Whatch reports the dataset to be empty after the fill. Does this SELECT statement really do any good? :confused: Thanks for comments, ideas or advise!

        S Offline
        S Offline
        Scott Serl
        wrote on last edited by
        #3

        This is usually a way to get an empty dataset with the correct stucture. It may be used for collecting and adding new rows to the database or perhaps merging data from another program layer before updating the database. I sometimes use this in large stored procedures which produce mutitable datasets; some of the tables may be empty, but my data layer expects the table structure to be there so I can add relationships, so I use a WHERE 0 = 1 to create an empty table.

        S 1 Reply Last reply
        0
        • S Scott Serl

          This is usually a way to get an empty dataset with the correct stucture. It may be used for collecting and adding new rows to the database or perhaps merging data from another program layer before updating the database. I sometimes use this in large stored procedures which produce mutitable datasets; some of the tables may be empty, but my data layer expects the table structure to be there so I can add relationships, so I use a WHERE 0 = 1 to create an empty table.

          S Offline
          S Offline
          SebbaP
          wrote on last edited by
          #4

          Thank you for your informative answer! However, let's extend my question somewhat. I understand why someone would want to do this, and when to use it. What I don't understand is why this is done in light of what the code does next. instanceDS = m_InstDb.GetInstanceDBDefinition(); string[] arl = new string[1]; arl[0]="T_Project"; instanceDS = m_InstDb.GetDataSetFromTables(arl); Doesn't the fourth line of code overwrite what was initially in 'instanceDS'? If it does, then the first line should be superflous, or am I wrong? Does preparing 'instanceDS' do any good when its about to be assigned something else? The first assignment to 'instanceDS' takes a long time (according a profiling tool I use), because the DataSet is "filled" with the structure of several tables, and my task as of now is to optimize the code for speed. Grateful for more help!

          S 1 Reply Last reply
          0
          • S SebbaP

            Thank you for your informative answer! However, let's extend my question somewhat. I understand why someone would want to do this, and when to use it. What I don't understand is why this is done in light of what the code does next. instanceDS = m_InstDb.GetInstanceDBDefinition(); string[] arl = new string[1]; arl[0]="T_Project"; instanceDS = m_InstDb.GetDataSetFromTables(arl); Doesn't the fourth line of code overwrite what was initially in 'instanceDS'? If it does, then the first line should be superflous, or am I wrong? Does preparing 'instanceDS' do any good when its about to be assigned something else? The first assignment to 'instanceDS' takes a long time (according a profiling tool I use), because the DataSet is "filled" with the structure of several tables, and my task as of now is to optimize the code for speed. Grateful for more help!

            S Offline
            S Offline
            Scott Serl
            wrote on last edited by
            #5

            Yes, that's not great code. In the most optomistic light, it looks like it might have been introduced during modification of the code (where it might have been used before the re-assignment). In the worst case, I would check if the variable instanceDS has a scope wider than the local procedure and make sure it is not used from within GetDataSetFromTables(). That would be REALLY bad. Also check that no other objects are affected from within GetInstanceDBDefinition(); it might be modifying some properties for later use(side effects).

            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