private IScalar getDolphinDBScalarBySystemType(Type stype, object value) { IScalar data = null; if (stype == Type.GetType("System.Boolean")) { data = new BasicBoolean(Convert.ToBoolean(value)); } else if (stype == Type.GetType("System.Byte")) { data = new BasicByte(Convert.ToByte(value)); } else if (stype == Type.GetType("System.Double")) { data = new BasicDouble(Convert.ToDouble(value)); } else if (stype == Type.GetType("System.DateTime")) { data = new BasicDateTime(Convert.ToDateTime(value)); } else if (stype == Type.GetType("System.TimeSpan")) { data = new BasicTime((TimeSpan)value); } else if (stype == Type.GetType("System.Int16")) { data = new BasicShort(Convert.ToInt16(value)); } else if (stype == Type.GetType("System.Int32")) { data = new BasicInt(Convert.ToInt32(value)); } else if (stype == Type.GetType("System.Int64")) { data = new BasicLong(Convert.ToInt64(value)); } else { data = new BasicString(value.ToString()); } return(data); }
/// <summary> /// transfer data to datatable /// </summary> /// <returns></returns> public DataTable toDataTable() { DataTable dt = new DataTable(_tableName); foreach (string fieldName in names_) { int i = name2index_[fieldName].Value; DATA_TYPE dtype = columns_[i].getDataType(); DataColumn dc = new DataColumn(fieldName, Utils.getSystemType(dtype)); dt.Columns.Add(dc); } if (columns_.Count == 0) { return(null); //table columns not exists } int rowCount = columns_[0].rows(); for (int rowIndex = 0; rowIndex < this.rows(); rowIndex++) { DataRow dr = dt.NewRow(); for (int colIndex = 0; colIndex < this.columns(); colIndex++) { DATA_TYPE dtype = columns_[colIndex].getDataType(); switch (dtype) { case DATA_TYPE.DT_BOOL: BasicBoolean bbobj = (BasicBoolean)columns_[colIndex].get(rowIndex); if (bbobj.isNull()) { dr[colIndex] = DBNull.Value; } else { dr[colIndex] = bbobj.getValue(); } break; case DATA_TYPE.DT_BYTE: BasicByte bobj = (BasicByte)columns_[colIndex].get(rowIndex); if (bobj.isNull()) { dr[colIndex] = DBNull.Value; } else { dr[colIndex] = bobj.getValue(); } break; case DATA_TYPE.DT_SHORT: BasicShort bsobj = (BasicShort)columns_[colIndex].get(rowIndex); if (bsobj.isNull()) { dr[colIndex] = DBNull.Value; } else { dr[colIndex] = bsobj.getValue(); } break; case DATA_TYPE.DT_INT: BasicInt biobj = (BasicInt)columns_[colIndex].get(rowIndex); if (biobj.isNull()) { dr[colIndex] = DBNull.Value; } else { dr[colIndex] = biobj.getValue(); } break; case DATA_TYPE.DT_LONG: BasicLong blobj = (BasicLong)columns_[colIndex].get(rowIndex); if (blobj.isNull()) { dr[colIndex] = DBNull.Value; } else { dr[colIndex] = blobj.getValue(); } break; case DATA_TYPE.DT_FLOAT: BasicFloat bfobj = (BasicFloat)columns_[colIndex].get(rowIndex); if (bfobj.isNull()) { dr[colIndex] = DBNull.Value; } else { dr[colIndex] = bfobj.getValue(); } break; case DATA_TYPE.DT_DOUBLE: BasicDouble bdobj = (BasicDouble)columns_[colIndex].get(rowIndex); if (bdobj.isNull()) { dr[colIndex] = DBNull.Value; } else { dr[colIndex] = bdobj.getValue(); } break; default: IScalar eobj = (IScalar)columns_[colIndex].get(rowIndex); if (eobj.isNull()) { dr[colIndex] = DBNull.Value; } else { dr[colIndex] = eobj.getString(); } break; } } dt.Rows.Add(dr); } return(dt); }