StarThrower.DataUtilities
2.0.0
dotnet add package StarThrower.DataUtilities --version 2.0.0
NuGet\Install-Package StarThrower.DataUtilities -Version 2.0.0
<PackageReference Include="StarThrower.DataUtilities" Version="2.0.0" />
<PackageVersion Include="StarThrower.DataUtilities" Version="2.0.0" />
<PackageReference Include="StarThrower.DataUtilities" />
paket add StarThrower.DataUtilities --version 2.0.0
#r "nuget: StarThrower.DataUtilities, 2.0.0"
#:package StarThrower.DataUtilities@2.0.0
#addin nuget:?package=StarThrower.DataUtilities&version=2.0.0
#tool nuget:?package=StarThrower.DataUtilities&version=2.0.0
StarThrower.DataUtilities
Data manipulation helpers with provider-agnostic database reader extensions supporting both legacy OleDb and modern DbDataReader APIs.
StarThrower.DataUtilities provides DataUtil, a static class of "safe getter" methods for reading typed values out of DataRow and DbDataReader objects — handling null/DBNull values, type conversion, and optional default values, so calling code doesn't need repetitive is DBNull checks scattered throughout.
Installation
dotnet add package StarThrower.DataUtilities
Platform note: This package depends on the
System.Data.OleDbNuGet package (for the obsoleteOleDbDataReaderoverloads described below), which is Windows-only. If you only use theDataRowandDbDataReaderoverloads, the rest of the library has no platform restrictions, but the package as a whole currently requires Windows.
DataUtil
Field Existence
| Method | Description |
|---|---|
CheckFieldExists(DbDataReader dr, string fieldName) |
Returns true if fieldName is one of the columns in dr. |
Typed Field Getters
For each supported type, three overload families are provided, all following the same pattern:
DataRowoverloads — operate onDataRow[fieldName].DbDataReaderoverloads — the modern, provider-agnostic API; operate ondr[field].OleDbDataReaderoverloads —[Obsolete]; thin wrappers that cast toDbDataReaderand delegate to theDbDataReaderoverload. Retained for backward compatibility; new code should use theDbDataReaderoverloads directly.
Each getter has a "default" overload (returns a built-in default — 0, false, string.Empty, DateTime.Now, etc. — if the field is null/DBNull) and an overload accepting an explicit defaultValue. Several also have a Nullable<T>-returning variant (GetNullable*Field) that returns null instead of a default.
| Type | Methods |
|---|---|
bool |
GetBooleanField, GetBoolField (with default overload) |
string |
GetStringField (with default overload) |
DateTime |
GetDateTimeField, GetNullableDateTimeField (each with default overload) |
float |
GetSingleField, GetFloatField (with default overload) |
double |
GetDoubleField, GetNullableDoubleField (each with default overload) |
long |
GetInt64Field, GetLongField (with default overload) |
int |
GetInt32Field, GetIntField, GetNullableIntField (each with default overload) |
short |
GetShortField, GetNullableShortField (each with default overload) |
Guid |
GetGuidField (DbDataReader only) |
byte[] |
GetBinaryField (DbDataReader only) |
using StarThrower.DataUtilities;
// DbDataReader (recommended)
while (reader.Read())
{
string name = DataUtil.GetStringField(reader, "Name");
int? age = DataUtil.GetNullableIntField(reader, "Age");
DateTime created = DataUtil.GetDateTimeField(reader, "CreatedDate", DateTime.UtcNow);
}
// DataRow
foreach (DataRow row in table.Rows)
{
bool active = DataUtil.GetBoolField(row, "IsActive");
}
DTNull
public static readonly DateTime DTNull = DateTime.MinValue;
A sentinel value used elsewhere in StarThrower.Utilities to represent a "null" date.
SQL DATETIME / TimeSpan Conversion
| Method | Description |
|---|---|
GetTimeSpanFromSQLDateTime(DateTime? sqlDateTime) |
Converts a SQL Server datetime value (stored relative to 1900-01-01) to a TimeSpan representing the elapsed time since that base date. Returns null if sqlDateTime is null. |
GetSQLDateTimeFromTimeSpan(TimeSpan? timeSpan) |
The inverse — adds timeSpan to 1900-01-01 to produce a DateTime. Returns null if timeSpan is null. |
Migrating from OleDbDataReader
If your code currently calls an OleDbDataReader overload (e.g. DataUtil.GetIntField(oleDbReader, "Count")), it will continue to work but is marked [Obsolete]. Since OleDbDataReader derives from DbDataReader, the fix is typically a no-op — the existing call resolves to the DbDataReader overload once the obsolete overload is removed from consideration, or you can pass the reader as DbDataReader explicitly.
Dependencies
System.Data.OleDb— required for the obsoleteOleDbDataReaderoverloads (Windows-only).
License
Copyright © 2026 Stephen Elmer. Licensed under the MIT License.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- System.Data.OleDb (>= 10.0.9)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 2.0.0 | 96 | 7/4/2026 |