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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. Order of insertion

Order of insertion

Scheduled Pinned Locked Moved ASP.NET
csharpasp-netdatabasegame-devhelp
9 Posts 5 Posters 1 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
    srikantha_nagaraj
    wrote on last edited by
    #1

    Hi, I am inserting in database using ASP.Net. But the insertion in the tables is not happening in the order of insertion. Please help me how to insert in order. for() { for() { for() { //method to insert(like Physics1A) } //method to insert(like Physics1) } //method to insert(like Physics) } I want in this order. Class Physics1A Physics1B Physics1C Physics1 Physics Chemistry1A Chemistry1B Chemistry1 Chemistry But it is not inserting in this order. Please help me.

    L A C A 4 Replies Last reply
    0
    • S srikantha_nagaraj

      Hi, I am inserting in database using ASP.Net. But the insertion in the tables is not happening in the order of insertion. Please help me how to insert in order. for() { for() { for() { //method to insert(like Physics1A) } //method to insert(like Physics1) } //method to insert(like Physics) } I want in this order. Class Physics1A Physics1B Physics1C Physics1 Physics Chemistry1A Chemistry1B Chemistry1 Chemistry But it is not inserting in this order. Please help me.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      The above tells us almost nothing about what you are trying to achieve. Post the code that you have tried, and pointing out the areas that do not work. Do not expect someone to write your code for you.

      1 Reply Last reply
      0
      • S srikantha_nagaraj

        Hi, I am inserting in database using ASP.Net. But the insertion in the tables is not happening in the order of insertion. Please help me how to insert in order. for() { for() { for() { //method to insert(like Physics1A) } //method to insert(like Physics1) } //method to insert(like Physics) } I want in this order. Class Physics1A Physics1B Physics1C Physics1 Physics Chemistry1A Chemistry1B Chemistry1 Chemistry But it is not inserting in this order. Please help me.

        A Offline
        A Offline
        Ashfield
        wrote on last edited by
        #3

        Why is the insert order important? The select should be responsible for the order the data is presented in.

        Bob Ashfield Consultants Ltd Proud to be a 2009 Code Project MVP

        S 1 Reply Last reply
        0
        • S srikantha_nagaraj

          Hi, I am inserting in database using ASP.Net. But the insertion in the tables is not happening in the order of insertion. Please help me how to insert in order. for() { for() { for() { //method to insert(like Physics1A) } //method to insert(like Physics1) } //method to insert(like Physics) } I want in this order. Class Physics1A Physics1B Physics1C Physics1 Physics Chemistry1A Chemistry1B Chemistry1 Chemistry But it is not inserting in this order. Please help me.

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          They will insert in the order you insert them. However, as someone else said, if the order they come out matters, and it's not alphabetical, you should use an index to sort by to specify the order from.

          Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

          1 Reply Last reply
          0
          • S srikantha_nagaraj

            Hi, I am inserting in database using ASP.Net. But the insertion in the tables is not happening in the order of insertion. Please help me how to insert in order. for() { for() { for() { //method to insert(like Physics1A) } //method to insert(like Physics1) } //method to insert(like Physics) } I want in this order. Class Physics1A Physics1B Physics1C Physics1 Physics Chemistry1A Chemistry1B Chemistry1 Chemistry But it is not inserting in this order. Please help me.

            A Offline
            A Offline
            Abhishek Sur
            wrote on last edited by
            #5

            //Method to insert Class in heading
            for() //will loop through {physics, chemistry ... }
            {
            for()
            {
            //Write Physics1A, 1B, 1C
            }
            //method to insert(like Physics1)
            //method to insert(like Physics)
            //Next loop again for Chemistry.. .and so on...
            }

            I think you need to do it by nesting two foreach loops...You dont need 3 nested loops for doing this.. . :rose::rose:

            Abhishek Sur


            My Latest Articles **Create CLR objects in SQL Server 2005 C# Uncommon Keywords Read/Write Excel using OleDB

            **Don't forget to click "Good Answer" if you like to.

            1 Reply Last reply
            0
            • A Ashfield

              Why is the insert order important? The select should be responsible for the order the data is presented in.

              Bob Ashfield Consultants Ltd Proud to be a 2009 Code Project MVP

              S Offline
              S Offline
              srikantha_nagaraj
              wrote on last edited by
              #6

              Actually i am selecting in order and insertion also happen in order as per as the code. But in the table instead of going to last row of the table it is inserting in the middle of the other rows. For example, it is inserting like this, Physics1A Physics1C Physics1B Chemistry Chemistry1 Physics Chemistry1C Physics1 Chemistry1A Chemistry1B But i want in this order. Physics1A Physics1B Physics1C Physics1 Physics Chemistry1A Chemistry1B Chemistry1 Chemistry I am using cmd.ExecuteNonQuery() for insertion is it giving a problem? Can i use anything other than that?

              A 1 Reply Last reply
              0
              • S srikantha_nagaraj

                Actually i am selecting in order and insertion also happen in order as per as the code. But in the table instead of going to last row of the table it is inserting in the middle of the other rows. For example, it is inserting like this, Physics1A Physics1C Physics1B Chemistry Chemistry1 Physics Chemistry1C Physics1 Chemistry1A Chemistry1B But i want in this order. Physics1A Physics1B Physics1C Physics1 Physics Chemistry1A Chemistry1B Chemistry1 Chemistry I am using cmd.ExecuteNonQuery() for insertion is it giving a problem? Can i use anything other than that?

                A Offline
                A Offline
                Ashfield
                wrote on last edited by
                #7

                Add an identity column to your table, then select back ordered by the identity column. I bet they are in the order you inserted them. A select without an order by is not guaranteed to return the records in any specific order (although generally it will be in the order of the PK idf there is one). Thats what is happening in this case, they are inserted in the order you do them (if its not the order you think then your code is wrong), but you do not define the order when you select them back, hence the difference.

                Bob Ashfield Consultants Ltd Proud to be a 2009 Code Project MVP

                S 1 Reply Last reply
                0
                • A Ashfield

                  Add an identity column to your table, then select back ordered by the identity column. I bet they are in the order you inserted them. A select without an order by is not guaranteed to return the records in any specific order (although generally it will be in the order of the PK idf there is one). Thats what is happening in this case, they are inserted in the order you do them (if its not the order you think then your code is wrong), but you do not define the order when you select them back, hence the difference.

                  Bob Ashfield Consultants Ltd Proud to be a 2009 Code Project MVP

                  S Offline
                  S Offline
                  srikantha_nagaraj
                  wrote on last edited by
                  #8

                  How to put an identity column to my table? Please help me. I don't have primary key defined. For this is it giving problem?

                  A 1 Reply Last reply
                  0
                  • S srikantha_nagaraj

                    How to put an identity column to my table? Please help me. I don't have primary key defined. For this is it giving problem?

                    A Offline
                    A Offline
                    Ashfield
                    wrote on last edited by
                    #9

                    I have told you what to do, and also that there is no problem. To find how to put an identity column on the table try google, I'm not dong the entire job for you.

                    Bob Ashfield Consultants Ltd Proud to be a 2009 Code Project MVP

                    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