Class DataUtils

Utility library for common data operations.

System.Object
  Westwind.Utilities.DataUtils
public static class DataUtils : object

Class Members

MemberDescription

MemberAccess

MemberPublicInstanceAccess

MinimumSqlDate

The default SQL date used by InitializeDataRowWithBlanks. Considered a blank date instead of null.

CloseConnection

Closes a connection

public static void CloseConnection(SqlCommand Command)

CopyDataRow

Copies the content of a data row to another. Runs through the target's fields and looks for fields of the same name in the source row. Structure must mathc or fields are skipped.

public static bool CopyDataRow(DataRow source,     DataRow target)

CopyObjectData

Copies the content of one object to another. The target object 'pulls' properties of the first.

public static void CopyObjectData(object source,     object target)

public static void CopyObjectData(object source,     object target,     BindingFlags memberAccess)

public static void CopyObjectData(object source,     object target,     string excludedProperties)

public static void CopyObjectData(object source,     object target,     string excludedProperties,     BindingFlags memberAccess)

CopyObjectFromDataRow

Populates an object passed in from values in a data row that's passed in.

public static void CopyObjectFromDataRow(DataRow row,     object targetObject,     MemberInfo[] cachedMemberInfo)

CopyObjectToDataRow

Copies the content of an object to a DataRow with matching field names. Both properties and fields are copied. If a field copy fails due to a type mismatch copying continues but the method returns false

public static bool CopyObjectToDataRow(DataRow row,     object target)

DataReaderToIEnumerable

Creates an IEnumerable of T from an open DataReader instance.

Note this method uses Reflection so this isn't a high performance operation, but it can be useful for generic data reader to entity conversions on the fly and with anonymous types.

public static IEnumerable DataReaderToIEnumerable(IDataReader reader,     string propertiesToSkip,     Dictionary<String,PropertyInfo> piList)

DataReaderToList

public static List DataReaderToList(IDataReader reader,     string propertiesToSkip,     Dictionary<String,PropertyInfo> piList)

DataReaderToObject

public static void DataReaderToObject(IDataReader reader,     object instance,     string propertiesToSkip,     Dictionary<String,PropertyInfo> piList)

DataReaderToObjectList

Creates a list of a given type from all the rows in a DataReader.

Note this method uses Reflection so this isn't a high performance operation, but it can be useful for generic data reader to entity conversions on the fly and with anonymous types.

public static List DataReaderToObjectList(IDataReader reader,     string propertiesToSkip,     Dictionary<String,PropertyInfo> piList)

DataTableToObjectList

Coverts a DataTable to a typed list of items

public static List DataTableToObjectList(DataTable dsTable)

DataTableToTypedList

Coverts a DataTable to a typed list of items

public static List DataTableToTypedList(DataTable dsTable)

DbTypeToDotNetType

Maps a DbType to a .NET native type

public static Type DbTypeToDotNetType(DbType sqlType)

DotNetTypeToDbType

Converts a .NET type into a DbType value

public static DbType DotNetTypeToDbType(Type type)

DotNetTypeToSqlType

Converts a .NET type into a SqlDbType.

public static SqlDbType DotNetTypeToSqlType(Type type)

GenerateUniqueId

public static string GenerateUniqueId(int stringSize,     string additionalCharacters)

GenerateUniqueNumericId

Generates a unique numeric ID. Generated off a GUID and returned as a 64 bit long value

public static long GenerateUniqueNumericId()

GetDataTable

Returns a DataTable from a Sql Command string passed in.

public static DataTable GetDataTable(string Tablename,     string ConnectionString,     string Sql,     SqlParameter[] Parameters)

GetDbProviderFactory

Loads a SQL Provider factory based on the DbFactory type name and assembly.

public static DbProviderFactory GetDbProviderFactory(string dbProviderFactoryTypename,     string assemblyName)

public static DbProviderFactory GetDbProviderFactory(DataAccessProviderTypes type)

public static DbProviderFactory GetDbProviderFactory(string providerName)

GetRandomNumber

Returns a random integer in a range of numbers a single seed value.

public static int GetRandomNumber(int min,     int max)

GetSqlCommand

Creates a Command object and opens a connection

public static SqlCommand GetSqlCommand(string ConnectionString,     string Sql,     SqlParameter[] Parameters)

GetSqlDataReader

Returns a SqlDataReader object from a SQL string.

Please ensure you close the Reader object

public static SqlDataReader GetSqlDataReader(string ConnectionString,     string Sql,     SqlParameter[] Parameters)

IndexOfByteArray

Returns an index into a byte array to find sequence of of bytes. Note: You can use Span.IndexOf() where available instead.

public static int IndexOfByteArray(Byte[] buffer,     Byte[] bufferToFind)

public static int IndexOfByteArray(Byte[] buffer,     string stringToFind,     Encoding encoding)

InitializeDataRowWithBlanks

Initializes a Datarow containing NULL values with 'empty' values instead. Empty values are: String - "" all number types - 0 or 0.00 DateTime - Value of MinimumSqlData (1/1/1900 by default); Boolean - false Binary values and timestamps are left alone

public static void InitializeDataRowWithBlanks(DataRow row)

SqlTypeToDotNetType

Maps a SqlDbType to a .NET type

public static Type SqlTypeToDotNetType(SqlDbType sqlType)

Requirements

Namespace: Westwind.Utilities
Assembly: westwind.utilities.dll

© West Wind Technologies, 2019 • Updated: 06/23/19
Comment or report problem with topic