DataRowEx.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Data;
  6. namespace Bowin.Common.Data
  7. {
  8. public static class DataRowEx
  9. {
  10. /// <summary>
  11. /// 获取指定列的值,并去掉两端的空格
  12. /// </summary>
  13. /// <param name="dr"></param>
  14. /// <param name="colName">列名</param>
  15. /// <returns></returns>
  16. public static string GetValue(this DataRow dr, string colName)
  17. {
  18. if (dr != null && dr[colName] != null)
  19. {
  20. return dr[colName].ToString().Trim();
  21. }
  22. else
  23. {
  24. return string.Empty;
  25. }
  26. }
  27. /// <summary>
  28. /// 获取指定列的值,并去掉两端的空格
  29. /// </summary>
  30. /// <param name="dr"></param>
  31. /// <param name="colName">列的索引</param>
  32. /// <returns></returns>
  33. public static string GetValue(this DataRow dr, int index)
  34. {
  35. if (dr != null && dr[index] != null)
  36. {
  37. return dr[index].ToString().Trim();
  38. }
  39. else
  40. {
  41. return string.Empty;
  42. }
  43. }
  44. }
  45. }