How to copy data table to arraylist ...?
-
Why not create separate DataRow arrays for each expression if you want to segregate them, or use OR in your select string if you want to group them all together? For example (using expresion segregation): DataTable dt = ...(your data table definition) DataRow[] drMobile = dt.Select("ItemName = 'mobile'"); DataRow[] drTV = dt.Select("ItemName = 'tv'"); DataRow[] drRadio = dt.Select("ItemName = 'radio'"); DataRow[] drComputer = dt.Select("ItemName = 'computer'"); or (grouping them all together): DataTable dt = ...(your data table definition) DataRow[] drows = dt.Select("ItemName = 'mobile' OR ItemName = 'tv' OR ItemName = 'radio' OR ItemName = 'computer'"); By the way, I don't recommend using ArrayList... instead, use Generics, for example, instead of using: ArrayList al = new ArrayList(); string v1 = "some text"; string v2 = "some more text"; string v3 = "even more text"; // you get the point... al.Add(v1); al.Add(v2); al.Add(v3); // etc. and then casting the content back to a string variable: string v1Str = (string)al[0]; ... Use Generics: List<string> al = new List<string>(); string v1 = "some text"; string v2 = "some more text"; string v3 = "even more text"; al.Add(v1); al.Add(v2); al.Add(v3); // etc. now, you don't have to cast the values back to a string when you retrieve them: string v1Str = al[0]; string v2Str = al[1]; ... Depending on what you are storing in the ArrayList, the cast operation can be very costly in terms of performance. Microsoft doesn't recommend using the ArrayList in .NET 2.0 and higher. -- modified at 22:03 Sunday 18th November, 2007
Thank you very much for your suggestion. Actually I have a data table with 10thousand records and now I have 4-5 items and I want to found any of item is missing or not ..? for that I have to traverse through data table, So I use array list which is having contains method which make traversing fast. Please give a good solution to resolve this issue. Also thanks for the guidance of using list instead of array list.
Regards Pankaj Joshi If you want to shape your dreams into reality, please wake-up...
-
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()..-----
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...
-
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...
-
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...
-
0 means: did not find any row for your criteria 1 means: found 1 row for your criteria
-----
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...
-
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...
-
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.
-----
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...
-
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...
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..
-----
-
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..
-----
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...
-
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...
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 -----
-
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 -----
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...