SqlConvert.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Data;
  5. using Oracle.ManagedDataAccess.Client;
  6. using MySql.Data.MySqlClient;
  7. using System.Data.Common;
  8. namespace Db_Core
  9. {
  10. public abstract class SqlConvert
  11. {
  12. public static DataTable ToDataTable(DbDataReader reader)
  13. {
  14. DataTable result = new DataTable();
  15. result.Load(reader);
  16. return result;
  17. }
  18. public static DataTable ToDataTable(OracleDataReader reader, Type dataTableType)
  19. {
  20. DataTable result = (DataTable)Activator.CreateInstance(dataTableType);
  21. result.Load(reader);
  22. return result;
  23. }
  24. public static int? ToInt32(object value)
  25. {
  26. if (value == Convert.DBNull)
  27. return null;
  28. if (value == null)
  29. return null;
  30. return Convert.ToInt32(value);
  31. }
  32. public static long? ToInt64(object value)
  33. {
  34. if (value == Convert.DBNull)
  35. return null;
  36. if (value == null)
  37. return null;
  38. return Convert.ToInt64(value);
  39. }
  40. public static DateTime? ToDateTime(object value)
  41. {
  42. if (value == Convert.DBNull)
  43. return null;
  44. if (value == null)
  45. return null;
  46. return DateTime.Parse(value.ToString());
  47. }
  48. public static string ToString(object value)
  49. {
  50. return value as string;
  51. }
  52. public static decimal? ToDecimal(object value)
  53. {
  54. if (value == Convert.DBNull)
  55. return null;
  56. if (value == null)
  57. return null;
  58. return Convert.ToDecimal(value);
  59. }
  60. }
  61. }