Class DataHelper
Methods to work with the Data.
public static class DataHelper
- Inheritance
-
objectDataHelper
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.")]
public static object ConvertValue(object value, Type type)
Parameters
valueobjectValue to convert
typeTypeTarget type
Returns
- object
DataSourceIsEmpty(DataSet)
Returns true if the given data source is empty.
public static bool DataSourceIsEmpty(DataSet dataSource)
Parameters
dataSourceDataSetData 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
dataSourceobjectData 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
dtDataTableData table
columnNamestringColumn name
columnTypeTypeColumn 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
dsDataSetDataSet with the data
rowActionAction<DataRow>Row action
rowConditionFunc<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
dtDataTableTable with the data
rowActionAction<DataRow>Row action
rowConditionFunc<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
drDataRowDataRow with the data
columnNamestringColumn name
defaultValueboolDefault 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
valueobjectValue 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
drDataRowDataRow with the data
columnNamestringColumn 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.")]
public static DataSet GetDataSetFromXml(string xmlData)
Parameters
xmlDatastringXML 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
drDataRowDataRow with the data
columnNamestringColumn name
defaultValueDateTimeDefault 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
drDataRowDataRow with the data
columnNamestringColumn name
defaultValueGuidDefault 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
drDataRowDataRow with the data
columnNamestringColumn name
defaultValueintDefault 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.")]
public static IList<int> GetIntegerValues(DataTable dt, string columnName)
Parameters
dtDataTableSource data table
columnNamestringColumn name
Returns
- IList<int>
GetItemsCount(object)
Gets the items count in the specified data source.
public static int GetItemsCount(object dataSource)
Parameters
dataSourceobjectData source
Returns
- int
GetNotEmpty(object, string)
Returns second parameter if the first is null or "".
public static string GetNotEmpty(object value, string defaultValue)
Parameters
valueobjectdefaultValuestring
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
valueobjectValue 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
pathstringOriginal 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
sizelongFile size in bytes
unitFileSizeUnitsEnumUnit 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
drDataRowDataRow with the data
columnNamestringColumn name
defaultValuestringDefault 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.")]
public static List<string> GetStringValues(DataTable dt, string columnName)
Parameters
dtDataTableSource data table
columnNamestringColumn name
Returns
- List<string>
IsEmpty(object)
Returns true, if the given value is empty (null, DBNull, or "").
public static bool IsEmpty(object value)
Parameters
valueobject
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.")]
public static bool IsValidID(int id)
Parameters
idintID 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.")]
public static void LockDataSet(DataSet ds)
Parameters
dsDataSetDataSet
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.")]
public static DataSet ReadDataSetFromXml(DataSet ds, XmlReader xml, object[] parameters, string rootNode, out List<string> updatedColumns, string cultureName = null)
Parameters
dsDataSetDataSet to read
xmlXmlReaderXML to read
parametersobject[]Callback parameters
rootNodestringName of the root node to check (if null not check is done)
updatedColumnsList<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
cultureNamestringName 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.")]
public static void RecomputeChildCount(DataTable parentObjects, string idColumn, string childCountColumn, DataTable childObjects, string parentIdColumn)
Parameters
parentObjectsDataTableData table containing parent objects.
idColumnstringIdentity column name in
parentObjectstable which the child objects reference.childCountColumnstringChild count column name where the computed child objects count is stored.
childObjectsDataTableData table containing child objects.
parentIdColumnstringForeign key column name in
childObjectstable 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.")]
public static void RestrictRows(DataSet ds, int topN)
Parameters
dsDataSetDataSet
topNintTop 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.")]
public static DataSet RestrictRows(DataSet ds, int offset, int maxRecords, ref int totalRecords)
Parameters
dsDataSetDataSet with the data
offsetintStarting offset
maxRecordsintMaximum number of the records
totalRecordsintReturns 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.")]
public static void SetColumnValues(DataTable dt, string column, object value)
Parameters
dtDataTableData table
columnstringColumn to set
valueobjectValue 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.")]
public static void SortDataTable(DataTable dt, string orderBy)
Parameters
dtDataTableTable to sort
orderBystringOrder 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.")]
public static void TransferTables(DataSet destinationDS, DataSet sourceDS)
Parameters
destinationDSDataSetDestination DataSet
sourceDSDataSetSource 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.")]
public static DataSet Union(DataSet ds1, DataSet ds2, string idColumn)
Parameters
ds1DataSetFirst DataSet
ds2DataSetSecond DataSet
idColumnstringID column name
Returns
- DataSet