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. General Programming
  3. C#
  4. How to copy data table to arraylist ...?

How to copy data table to arraylist ...?

Scheduled Pinned Locked Moved C#
data-structuresregextutorialquestion
17 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 SABhatti

    well you should be able to add multiple expressions using and/or e.g. expression = "ItemName = 'mobile' or ItemName = 'tv' or ItemName = 'radio' or ItemName = 'computer'"; you can try in also like "ItemName in('mobile','tv', 'radio', 'computer')" and if you have any primary key in the table then use DataTable.Rows.Find instead of .Select()..

    -----

    P Offline
    P Offline
    Pankaj Joshi
    wrote on last edited by
    #8

    Sir, foundRows.Length returns what...? 0 means...? 1 means...?:confused:

    Regards Pankaj Joshi If you want to shape your dreams into reality, please wake-up...

    S 1 Reply Last reply
    0
    • P Pankaj Joshi

      Sir, foundRows.Length returns what...? 0 means...? 1 means...?:confused:

      Regards Pankaj Joshi If you want to shape your dreams into reality, please wake-up...

      S Offline
      S Offline
      SABhatti
      wrote on last edited by
      #9

      0 means: did not find any row for your criteria 1 means: found 1 row for your criteria

      -----

      P 1 Reply Last reply
      0
      • P Pankaj Joshi

        Dear SABhatti, Actually I want to know weather or not any item is mismatch. Suppose I have 5 items and 2 items are missing then the functions should say their are 2 items are missing.

        Regards Pankaj Joshi If you want to shape your dreams into reality, please wake-up...

        S Offline
        S Offline
        SABhatti
        wrote on last edited by
        #10

        well you can check the number of rows (foundRows.Length) found and show the message accordingly

        -----

        1 Reply Last reply
        0
        • S SABhatti

          0 means: did not find any row for your criteria 1 means: found 1 row for your criteria

          -----

          P Offline
          P Offline
          Pankaj Joshi
          wrote on last edited by
          #11

          Ok. Then it is difficult to find which item is missing...?

          Regards Pankaj Joshi If you want to shape your dreams into reality, please wake-up...

          S 1 Reply Last reply
          0
          • P Pankaj Joshi

            Ok. Then it is difficult to find which item is missing...?

            Regards Pankaj Joshi If you want to shape your dreams into reality, please wake-up...

            S Offline
            S Offline
            SABhatti
            wrote on last edited by
            #12

            well I am sorry, but are you a programmer? if you want that then you can find all rows one by one and see what you are missing. Or you can compare the results again for your criteria and see what you are missing.

            -----

            P 1 Reply Last reply
            0
            • S SABhatti

              well I am sorry, but are you a programmer? if you want that then you can find all rows one by one and see what you are missing. Or you can compare the results again for your criteria and see what you are missing.

              -----

              P Offline
              P Offline
              Pankaj Joshi
              wrote on last edited by
              #13

              YES YES YES !!!! :omg: I am a programmer , and facing problems so ask this question. Why are you asking that...? Any prob...?

              Regards Pankaj Joshi If you want to shape your dreams into reality, please wake-up...

              S 1 Reply Last reply
              0
              • P Pankaj Joshi

                YES YES YES !!!! :omg: I am a programmer , and facing problems so ask this question. Why are you asking that...? Any prob...?

                Regards Pankaj Joshi If you want to shape your dreams into reality, please wake-up...

                S Offline
                S Offline
                SABhatti
                wrote on last edited by
                #14

                well, sorry if you are offended. but normally people ask for guidance/hints in the forums and you can't even think/do this simple thing after you have all the code to find the results... all code was there and now you just had to think a very little to do your task but you posted the next question without thinking ... if you really want to learn then please spend some time in making your logic on paper before start coding..

                -----

                P 1 Reply Last reply
                0
                • S SABhatti

                  well, sorry if you are offended. but normally people ask for guidance/hints in the forums and you can't even think/do this simple thing after you have all the code to find the results... all code was there and now you just had to think a very little to do your task but you posted the next question without thinking ... if you really want to learn then please spend some time in making your logic on paper before start coding..

                  -----

                  P Offline
                  P Offline
                  Pankaj Joshi
                  wrote on last edited by
                  #15

                  Yes, sir you are right. Actually what is happening, I am having more than 23,000 items and I don't want to traverse. I search a lot but no good solution is found. And if I am having 10 records in a new order then I have to traverse through the 23thousand records so I ask a solution. The solution you provide is good but I unable to understand how I can found the unmatched items...? At the end of all.... I am very very sorry if I hurt you any way. :rose:

                  Regards Pankaj Joshi If you want to shape your dreams into reality, please wake-up...

                  S 1 Reply Last reply
                  0
                  • P Pankaj Joshi

                    Yes, sir you are right. Actually what is happening, I am having more than 23,000 items and I don't want to traverse. I search a lot but no good solution is found. And if I am having 10 records in a new order then I have to traverse through the 23thousand records so I ask a solution. The solution you provide is good but I unable to understand how I can found the unmatched items...? At the end of all.... I am very very sorry if I hurt you any way. :rose:

                    Regards Pankaj Joshi If you want to shape your dreams into reality, please wake-up...

                    S Offline
                    S Offline
                    SABhatti
                    wrote on last edited by
                    #16

                    well without going in detail here is the quick fix for you: // flags to check if found bool testMatched, test1Matched, test2Matched, test4Matched; // by default none found testMatched = false; test1Matched = false; test2Matched = false; test4Matched = false; foundRows = datatable.Select("itemName='test' or itemName='test1' or itemName='test2' or itemName='test4'"); // if any row found if(foundRows.Length > 0) { // loop through all found rows for(int i=0; i hope this will help you -----

                    P 1 Reply Last reply
                    0
                    • S SABhatti

                      well without going in detail here is the quick fix for you: // flags to check if found bool testMatched, test1Matched, test2Matched, test4Matched; // by default none found testMatched = false; test1Matched = false; test2Matched = false; test4Matched = false; foundRows = datatable.Select("itemName='test' or itemName='test1' or itemName='test2' or itemName='test4'"); // if any row found if(foundRows.Length > 0) { // loop through all found rows for(int i=0; i hope this will help you -----

                      P Offline
                      P Offline
                      Pankaj Joshi
                      wrote on last edited by
                      #17

                      Thanks for your reply sir... I also create a logic can you check it for me? //Filling the datatable dataTableItems.... ///Create the generic object List listNoOfItems = new List(); //Adding the search item into the list listNoOfItems.Add("Item1"); listNoOfItems.Add("Item2"); for (int listIndex = 0; listIndex <= listNoOfItems.Count - 1; listIndex++) { DataRow[] foundRows; //Finding the rows.... foundRows = dataTableItems.Select("ItemName = '" + listNoOfItems[listIndex] + "'"); if (foundRows.Length <= 0) { MessageBox.Show("Not found " + listNoOfItems[listIndex]); } else { MessageBox.Show("Found " + foundRows[0]["ItemName"].ToString()); } } Will this code is OK...?

                      Regards Pankaj Joshi If you want to shape your dreams into reality, please wake-up...

                      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