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.")]
[ObsoleteSince(28, 3)]
public static object ConvertValue(object value, Type type)
Parameters
value
objectValue to convert
type
TypeTarget type
Returns
- object
DataSourceIsEmpty(DataSet)
Returns true if the given data source is empty.
public static bool DataSourceIsEmpty(DataSet dataSource)
Parameters
dataSource
DataSetData 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
objectData 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
DataTableData table
columnName
stringColumn name
columnType
TypeColumn 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
DataSetDataSet 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
DataTableTable 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
DataRowDataRow with the data
columnName
stringColumn name
defaultValue
boolDefault 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
objectValue 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
DataRowDataRow with the data
columnName
stringColumn 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
stringXML 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
DataRowDataRow with the data
columnName
stringColumn name
defaultValue
DateTimeDefault 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
DataRowDataRow with the data
columnName
stringColumn name
defaultValue
GuidDefault 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
DataRowDataRow with the data
columnName
stringColumn name
defaultValue
intDefault 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
DataTableSource data table
columnName
stringColumn name
Returns
- IList<int>
GetItemsCount(object)
Gets the items count in the specified data source.
public static int GetItemsCount(object dataSource)
Parameters
dataSource
objectData 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
objectdefaultValue
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
objectValue 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
stringOriginal 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
longFile size in bytes
unit
FileSizeUnitsEnumUnit 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
DataRowDataRow with the data
columnName
stringColumn name
defaultValue
stringDefault 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
DataTableSource data table
columnName
stringColumn 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
intID 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
DataSetDataSet
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
DataSetDataSet to read
xml
XmlReaderXML to read
parameters
object[]Callback parameters
rootNode
stringName 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
stringName 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
DataTableData table containing parent objects.
idColumn
stringIdentity column name in
parentObjects
table which the child objects reference.childCountColumn
stringChild count column name where the computed child objects count is stored.
childObjects
DataTableData table containing child objects.
parentIdColumn
stringForeign 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
DataSetDataSet
topN
intTop 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
DataSetDataSet with the data
offset
intStarting offset
maxRecords
intMaximum number of the records
totalRecords
intReturns 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
DataTableData table
column
stringColumn to set
value
objectValue 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
DataTableTable to sort
orderBy
stringOrder 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
DataSetDestination DataSet
sourceDS
DataSetSource 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
DataSetFirst DataSet
ds2
DataSetSecond DataSet
idColumn
stringID column name
Returns
- DataSet