Advertisement
msmosso

Untitled

Jan 20th, 2017
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. public List<Dictionary<string, string>> RunSql(string sql)
  2. {
  3. List<Dictionary<string, string>> row = new List<Dictionary<string, string>>();
  4. SqlDataReader reader;
  5. SqlCommand cmd = this.getSqlCommand();
  6. cmd.CommandText = sql;
  7. if (transaction == false)
  8. {
  9. if (this.db.State == ConnectionState.Closed)
  10. {
  11. this.db.Open();
  12. }
  13. }
  14.  
  15. reader = cmd.ExecuteReader();
  16.  
  17. try
  18. {
  19. while (reader.Read())
  20. {
  21. Dictionary<string, string> coluna = new Dictionary<string, string>();
  22. for (int x = 0; x < reader.FieldCount; x++)
  23. {
  24. Type a = typeof(System.Byte[]);
  25. Object valor = reader[reader.GetName(x)];
  26. if (reader[reader.GetName(x)].GetType() == a)
  27. {
  28. System.Byte[] bytes = (System.Byte[])valor;
  29. coluna[reader.GetName(x)] = BitConverter.ToString(bytes);
  30. }
  31. else
  32. {
  33. coluna[reader.GetName(x)] = valor.ToString();
  34. }
  35.  
  36. }
  37. row.Add(coluna);
  38. }
  39. if (transaction == false)
  40. {
  41. this.db.Close();
  42. }
  43. reader.Close();
  44. }
  45. catch (Exception e)
  46. {
  47. reader.Close();
  48. }
  49. return row;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement