Table of Contents

Class DataHelper

Namespace
CMS.Helpers
Assembly
CMS.Helpers.dll

Methods to work with the Data.

public static class DataHelper
Inheritance
object
DataHelper

Fields

FAKE_ID

Fake ID to use when the ID column requires a value, and needs to be faked

public const int FAKE_ID = 2147483647

Field Value

int

Methods

ConvertValue(object, Type)

Converts the value to a specific type.

[Obsolete("Method was not intended for public use and will be removed in the next version.")]
[ObsoleteSince(28, 3)]
public static object ConvertValue(object value, Type type)

Parameters

value object

Value to convert

type Type

Target type

Returns

object

DataSourceIsEmpty(DataSet)

Returns true if the given data source is empty.

public static bool DataSourceIsEmpty(DataSet dataSource)

Parameters

dataSource DataSet

Data source to check for emptiness

Returns

bool

DataSourceIsEmpty(object)

Returns true if the given data source is empty.

public static bool DataSourceIsEmpty(object dataSource)

Parameters

dataSource object

Data source to check for emptiness

Returns

bool

EnsureColumn(DataTable, string, Type)

Ensures specified column.

public static int EnsureColumn(DataTable dt, string columnName, Type columnType)

Parameters

dt DataTable

Data table

columnName string

Column name

columnType Type

Column type

Returns

int

ForEachRow(DataSet, Action<DataRow>, Func<DataRow, bool>)

Executes the given action for each row in the given DataSet

public static void ForEachRow(DataSet ds, Action<DataRow> rowAction, Func<DataRow, bool> rowCondition = null)

Parameters

ds DataSet

DataSet with the data

rowAction Action<DataRow>

Row action

rowCondition Func<DataRow, bool>

Row condition to filter rows

ForEachRow(DataTable, Action<DataRow>, Func<DataRow, bool>)

Executes the given action for each row in the given DataSet

public static void ForEachRow(DataTable dt, Action<DataRow> rowAction, Func<DataRow, bool> rowCondition = null)

Parameters

dt DataTable

Table with the data

rowAction Action<DataRow>

Row action

rowCondition Func<DataRow, bool>

Row condition to filter rows

GetBoolValue(DataRow, string, bool)

Gets the bool variable from given DataRow.

public static bool GetBoolValue(DataRow dr, string columnName, bool defaultValue = false)

Parameters

dr DataRow

DataRow with the data

columnName string

Column name

defaultValue bool

Default value

Returns

bool

GetDBNull(object)

Converts the standard null value to DBNull.value, keeps the object value if not null.

public static object GetDBNull(object value)

Parameters

value object

Value to convert

Returns

object

GetDataRowValue(DataRow, string)

Returns the value from the DataRow field, or DBNull.Value if the field does not exist in the datarow.

public static object GetDataRowValue(DataRow dr, string columnName)

Parameters

dr DataRow

DataRow with the data

columnName string

Column name

Returns

object

GetDataSetFromXml(string)

Gets DataSet from the given XML string.

[Obsolete("Method was not intended for public use and will be removed in the next version.")]
[ObsoleteSince(28, 3)]
public static DataSet GetDataSetFromXml(string xmlData)

Parameters

xmlData string

XML data

Returns

DataSet

GetDateTimeValue(DataRow, string, DateTime)

Gets the DateTime variable from given DataRow.

public static DateTime GetDateTimeValue(DataRow dr, string columnName, DateTime defaultValue = default)

Parameters

dr DataRow

DataRow with the data

columnName string

Column name

defaultValue DateTime

Default value

Returns

DateTime

GetGuidValue(DataRow, string, Guid)

Gets the guid variable from given DataRow.

public static Guid GetGuidValue(DataRow dr, string columnName, Guid defaultValue = default)

Parameters

dr DataRow

DataRow with the data

columnName string

Column name

defaultValue Guid

Default value

Returns

Guid

GetIntValue(DataRow, string, int)

Gets the integer variable from given DataRow.

public static int GetIntValue(DataRow dr, string columnName, int defaultValue = 0)

Parameters

dr DataRow

DataRow with the data

columnName string

Column name

defaultValue int

Default value

Returns

int

GetIntegerValues(DataTable, string)

Gets the array of integer values from the given data table.

[Obsolete("Method was not intended for public use and will be removed in the next version.")]
[ObsoleteSince(28, 3)]
public static IList<int> GetIntegerValues(DataTable dt, string columnName)

Parameters

dt DataTable

Source data table

columnName string

Column name

Returns

IList<int>

GetItemsCount(object)

Gets the items count in the specified data source.

public static int GetItemsCount(object dataSource)

Parameters

dataSource object

Data source

Returns

int

GetNotEmpty(object, string)

Returns second parameter if the first is null or "".

public static string GetNotEmpty(object value, string defaultValue)

Parameters

value object
defaultValue string

Returns

string

GetNull(object)

Converts the DBNull.value to standard null, keeps the object value if not null.

public static object GetNull(object value)

Parameters

value object

Value to convert

Returns

object

GetParentPath(string)

Returns the parent path for the specified path (any kind of path with "/" as a separator)

public static string GetParentPath(string path)

Parameters

path string

Original path

Returns

string

GetSizeString(long, FileSizeUnitsEnum)

Returns the string for the specified file size.

public static string GetSizeString(long size, FileSizeUnitsEnum unit = FileSizeUnitsEnum.Automatic)

Parameters

size long

File size in bytes

unit FileSizeUnitsEnum

Unit in which you want the result

Returns

string

GetStringValue(DataRow, string, string)

Gets the string variable from given DataRow.

public static string GetStringValue(DataRow dr, string columnName, string defaultValue = "")

Parameters

dr DataRow

DataRow with the data

columnName string

Column name

defaultValue string

Default value

Returns

string

GetStringValues(DataTable, string)

Gets the array of string values from the given data table.

[Obsolete("Method was not intended for public use and will be removed in the next version.")]
[ObsoleteSince(28, 3)]
public static List<string> GetStringValues(DataTable dt, string columnName)

Parameters

dt DataTable

Source data table

columnName string

Column name

Returns

List<string>

IsEmpty(object)

Returns true, if the given value is empty (null, DBNull, or "").

public static bool IsEmpty(object value)

Parameters

value object

Returns

bool

IsValidID(int)

Returns true if the given value is a valid ID

[Obsolete("Method was not intended for public use and will be removed in the next version.")]
[ObsoleteSince(28, 3)]
public static bool IsValidID(int id)

Parameters

id int

ID to check

Returns

bool

LockDataSet(DataSet)

Makes the given DataSet read-only

[Obsolete("Method was not intended for public use and will be removed in the next version.")]
[ObsoleteSince(28, 3)]
public static void LockDataSet(DataSet ds)

Parameters

ds DataSet

DataSet

ReadDataSetFromXml(DataSet, XmlReader, object[], string, out List<string>, string)

Reads the DataSet from given XML reader.

[Obsolete("Method was not intended for public use and will be removed in the next version.")]
[ObsoleteSince(28, 3)]
public static DataSet ReadDataSetFromXml(DataSet ds, XmlReader xml, object[] parameters, string rootNode, out List<string> updatedColumns, string cultureName = null)

Parameters

ds DataSet

DataSet to read

xml XmlReader

XML to read

parameters object[]

Callback parameters

rootNode string

Name of the root node to check (if null not check is done)

updatedColumns List<string>

List of columns present in the xml (not all columns from DataSet have to be also in containing xml), this list is needed for update mode in CMSHierarchyHelper

cultureName string

Name of the culture to use for parsing double, decimal and datetime values. English culture is used if not specified

Returns

DataSet

RecomputeChildCount(DataTable, string, string, DataTable, string)

Re-computes count of child objects in parentObjects data table's childCountColumn column.

[Obsolete("Method was not intended for public use and will be removed in the next version.")]
[ObsoleteSince(28, 3)]
public static void RecomputeChildCount(DataTable parentObjects, string idColumn, string childCountColumn, DataTable childObjects, string parentIdColumn)

Parameters

parentObjects DataTable

Data table containing parent objects.

idColumn string

Identity column name in parentObjects table which the child objects reference.

childCountColumn string

Child count column name where the computed child objects count is stored.

childObjects DataTable

Data table containing child objects.

parentIdColumn string

Foreign key column name in childObjects table which references the parent.

RestrictRows(DataSet, int)

Restricts the number of rows to the top N items.

[Obsolete("Method was not intended for public use and will be removed in the next version.")]
[ObsoleteSince(28, 3)]
public static void RestrictRows(DataSet ds, int topN)

Parameters

ds DataSet

DataSet

topN int

Top N items

RestrictRows(DataSet, int, int, ref int)

Restricts the given DataSet to only given rows starting with the offset, and leaving only maximum defined number of rows.

[Obsolete("Method was not intended for public use and will be removed in the next version.")]
[ObsoleteSince(28, 3)]
public static DataSet RestrictRows(DataSet ds, int offset, int maxRecords, ref int totalRecords)

Parameters

ds DataSet

DataSet with the data

offset int

Starting offset

maxRecords int

Maximum number of the records

totalRecords int

Returns the total number of available records

Returns

DataSet

Returns the same DataSet object

SetColumnValues(DataTable, string, object)

Sets column values to specified value.

[Obsolete("Method was not intended for public use and will be removed in the next version.")]
[ObsoleteSince(28, 3)]
public static void SetColumnValues(DataTable dt, string column, object value)

Parameters

dt DataTable

Data table

column string

Column to set

value object

Value to set

SortDataTable(DataTable, string)

Sorts the Data table using given OrderBy expression.

[Obsolete("Method was not intended for public use and will be removed in the next version.")]
[ObsoleteSince(28, 3)]
public static void SortDataTable(DataTable dt, string orderBy)

Parameters

dt DataTable

Table to sort

orderBy string

Order by expression

TransferTables(DataSet, DataSet)

Transfers tables from source DataSet to the destination DataSet.

[Obsolete("Method was not intended for public use and will be removed in the next version.")]
[ObsoleteSince(28, 3)]
public static void TransferTables(DataSet destinationDS, DataSet sourceDS)

Parameters

destinationDS DataSet

Destination DataSet

sourceDS DataSet

Source DataSet

Union(DataSet, DataSet, string)

Creates the union of two Datasets, the values are compared for uniqueness by the given ID column name.

[Obsolete("Method was not intended for public use and will be removed in the next version.")]
[ObsoleteSince(28, 3)]
public static DataSet Union(DataSet ds1, DataSet ds2, string idColumn)

Parameters

ds1 DataSet

First DataSet

ds2 DataSet

Second DataSet

idColumn string

ID column name

Returns

DataSet