Guest User

Untitled

a guest
Jun 19th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. ------------------------------
  2. | id | fecha |
  3. ------------------------------
  4. | 1 | 2018-06-18 14:30:00 |
  5. | 2 | 2018-06-18 14:31:40 |
  6. ------------------------------
  7.  
  8. public static DataTable Ultimo()
  9. {
  10. DataTable DtResultado = new DataTable("ultimo");
  11. NpgsqlConnection SqlCon = new NpgsqlConnection(Conexion.Cn);
  12. NpgsqlCommand SqlDat = new NpgsqlCommand(String.Format("select * from " + table + " order by fecha desc limit 1"), SqlCon);
  13. SqlCon.Open();
  14. NpgsqlDataReader dr = SqlDat.ExecuteReader(CommandBehavior.CloseConnection);
  15. DtResultado.Load(dr);
  16. dr.Close();
  17. SqlDat.Dispose();
  18. SqlCon.Close();
  19. return DtResultado;
  20. }
  21.  
  22. public static DataTable PorFechaExacta(string date)
  23. {
  24. DataTable DtResultado = new DataTable("fechaExacta");
  25. NpgsqlConnection SqlCon = new NpgsqlConnection(Conexion.Cn);
  26. Console.Write(date);
  27. NpgsqlCommand SqlDat = new NpgsqlCommand(String.Format("select * from " + table + " where date(fecha)='"+date+"'"), SqlCon);
  28. SqlCon.Open();
  29. NpgsqlDataReader dr = SqlDat.ExecuteReader(CommandBehavior.CloseConnection);
  30. DtResultado.Load(dr);
  31. dr.Close();
  32. SqlDat.Dispose();
  33. SqlCon.Close();
  34. return DtResultado;
  35. }
Add Comment
Please, Sign In to add comment