Bestimmen Sie, ob DataColumn numerisch ist

Gibt es eine bessere Möglichkeit als diese, um zu überprüfen, ob eine DataColumn in eine DataTable ist eine numerische (kommen aus einer SQL Server-Datenbank)?

  Database db = DatabaseFactory.CreateDatabase();
  DbCommand cmd = db.GetStoredProcCommand("Get_Some_Data");
  DataSet ds = db.ExecuteDataSet(cmd);

  foreach (DataTable tbl in ds.Tables) {
    foreach (DataColumn col in tbl.Columns) {
      if (col.DataType == typeof(System.Single)
        || col.DataType == typeof(System.Double)
        || col.DataType == typeof(System.Decimal)
        || col.DataType == typeof(System.Byte)
        || col.DataType == typeof(System.Int16)
        || col.DataType == typeof(System.Int32)
        || col.DataType == typeof(System.Int64)) {
        //this column is numeric
      } else {
        //this column is not numeric
      }
    }
  }

InformationsquelleAutor der Frage JustinStolle | 2009-11-12

Schreibe einen Kommentar