Convert-Column-Type
Command Description
Convert the data type of a database column
Command Prototype
Datatable.ConvertColumnDataType(dtTable,column,strType,bRaiseExcept,defaultValue)
Parameter Description
Parameter | Required | Type | Default | Description |
---|---|---|---|---|
dtTable | True | expression | objDatatable | The data table to be filtered |
column | True | string | "" | The data column to be converted. A single column name or multiple column names are all acceptable |
strType | True | enum | "float" | The target data type to convert to |
bRaiseExcept | True | boolean | None | Whether to throw an error when the conversion fails |
defaultValue | True | expression | null | When conversion failure exists and it is set not to throw errors, the values can be all converted to fill values |
Demo
aryData = [["a", 1], ["b", 2], ["c", 3], ["d", 1]]
aryColumns = ["letter", "number"]
objDatatable = Datatable.BuildDataTable(aryData,aryColumns)
Datatable.ConvertColumnDataType(objDatatable,"number","float",false,null)
TracePrint(objDatatable)
/*
letter number
0 a 1.0
1 b 2.0
2 c 3.0
3 d 1.0
*/