Skip to main content

Convert-Column-Type

Command Description

Convert the data type of a database column

Command Prototype

Datatable.ConvertColumnDataType(dtTable,column,strType,bRaiseExcept,defaultValue)

Parameter Description

ParameterRequiredTypeDefaultDescription
dtTableTrueexpressionobjDatatableThe data table to be filtered
columnTruestring""The data column to be converted. A single column name or multiple column names are all acceptable
strTypeTrueenum"float"The target data type to convert to
bRaiseExceptTruebooleanNoneWhether to throw an error when the conversion fails
defaultValueTrueexpressionnullWhen 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
*/