Guest User

Untitled

a guest
Aug 16th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. How can I read string value and store it in a array using data reader
  2. string[] result = null;
  3. while (reader.Read())
  4. {
  5. result = Convert.ToString[](reader["RoleID"]);
  6. }
  7. reader.Close();
  8.  
  9. var results = new List<string>();
  10. while (reader.Read())
  11. {
  12. results.Add(reader["RoleID"].ToString());
  13. }
  14.  
  15. // results now holds all of the RoleID values in the reader
  16.  
  17. string check = "something";
  18. if (results.Any(item => item.Equals(check)))
  19. {
  20. // results contains the value in check
  21. }
  22.  
  23. // or use all items that equal check
  24. foreach (var item in results.Where(obj => obj.Equals(check))
  25. {
  26. // do something with each item that equals check
  27. }
  28.  
  29. var result= new ArrayList();
  30. while (reader.Read())
  31. {
  32. result.Add(Convert.ToString[](reader["RoleID"]));
  33. }reader.Close();
  34.  
  35. var results = new List<string>();
  36. while( reader.Read() ){
  37. results.Add(reader["RoleID"].ToString());
  38. }
  39.  
  40. foreach(var result in results) {
  41. if(result == "check") {
  42. // do something
  43. }
  44. }
Add Comment
Please, Sign In to add comment