Guest User

Untitled

a guest
Nov 22nd, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.28 KB | None | 0 0
  1. public void GetRootDirectory()
  2. {
  3. p.Con.Open();
  4. Console.WriteLine("Üdv {0}!n", GetUsersFullName());
  5. DataTable dt = new DataTable();
  6. var query = "SELECT Mappa_id FROM Mappastruktúra WHERE (Parent_id IS NULL OR Parent_id = 0) AND username = @username";
  7. var sda = new SqlDataAdapter(query, p.Con);
  8.  
  9. //SQL Injection Protection
  10. sda.SelectCommand.Parameters.AddWithValue("@username", SqlDbType.VarChar);
  11. sda.SelectCommand.Parameters["@username"].Value = p.Getlgduser();
  12. sda.Fill(dt);
  13. if (dt.Rows.Count == 0)
  14. {
  15. Console.WriteLine("Még nincsenek feltöltött elemek!");
  16. }
  17. else
  18. {
  19. sorszam = dt.Rows.Count;
  20. oszlopszam = dt.Columns.Count;
  21.  
  22. for (int j = 0; j < sorszam; j++)
  23. {
  24. IdList.Add((int)dt.Rows[j][0]);
  25. }
  26. //Thats where i get system out of range exception
  27. for (int i = 0; i < IdList.Count; i++)
  28. {
  29. FolderList[i] = GetFName(IdList[i]);
  30. }
  31. Console.WriteLine("FolerList:");
  32. foreach (var a in FolderList)
  33. {
  34. Console.WriteLine(a);
  35. }
  36. FolderList.Add("---------");
  37. FolderList.Add("Új Mappa");
  38. FolderList.Add("Feltöltés");
  39. FolderList.Add("Letöltés");
  40. m.DebugTable(dt);
  41. }
  42. p.Con.Close();
  43. }
  44.  
  45. public string GetFName(int fname)
  46. {
  47. p.Con.Open();
  48. var dt = new DataTable();
  49. string query = "SELECT FolderName FROM Mappastruktúra WHERE Mappa_id = @mappa_id";
  50. string query2 = "SELECT FolderName FROM Mappastruktúra WHERE Mappa_id = @mappa_id";
  51. SqlCommand cmd = new SqlCommand(query,p.Con);
  52. //SQL Injection Protection
  53. cmd.Parameters.AddWithValue("@mappa_id", SqlDbType.Int);
  54. cmd.Parameters["@mappa_id"].Value = fname;
  55. try
  56. {
  57. string name = cmd.ExecuteScalar().ToString();
  58. p.Con.Close();
  59. return name;
  60. }
  61. catch (Exception e)
  62. {
  63. p.Con.Close();
  64. Console.WriteLine(e);
  65. return null;
  66. }
Add Comment
Please, Sign In to add comment