Starb.DataLibrary 2.0.0.26263

dotnet add package Starb.DataLibrary --version 2.0.0.26263
                    
NuGet\Install-Package Starb.DataLibrary -Version 2.0.0.26263
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Starb.DataLibrary" Version="2.0.0.26263" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Starb.DataLibrary" Version="2.0.0.26263" />
                    
Directory.Packages.props
<PackageReference Include="Starb.DataLibrary" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Starb.DataLibrary --version 2.0.0.26263
                    
#r "nuget: Starb.DataLibrary, 2.0.0.26263"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Starb.DataLibrary@2.0.0.26263
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Starb.DataLibrary&version=2.0.0.26263
                    
Install as a Cake Addin
#tool nuget:?package=Starb.DataLibrary&version=2.0.0.26263
                    
Install as a Cake Tool

Starb.DataLibrary

Provider-agnostic ADO.NET data access for .NET Framework and .NET, plus the reflection, logging and resource helpers the rest of the Starbook libraries build on.

One API works against SQL Server, OLE DB, ODBC, Oracle and Firebird: the configured provider decides parameter syntax (@Name, :Name or ?), identifier delimiters and the provider type enum, so call sites do not change when the database does.

Target frameworks: net461, net8.0-windows · Root namespace: DataLibraryStarb

Install

dotnet add package Starb.DataLibrary

Configure

The provider comes from a named connection string, ConnectionString by default:

<connectionStrings>
  <add name="ConnectionString"
       connectionString="Data Source=(local);Initial Catalog=Sales;Integrated Security=True"
       providerName="System.Data.SqlClient" />
</connectionStrings>
DataBase.ConnectionStringToRead = "ConnectionString";   // pick another entry
DataBase.ConnectionString = new ConnectionStringSettings(...);  // or set one directly
DataBase.CommandTimeOut = 60;
DataBase.ReuseConnection = true;                        // keep one connection per session

{APP_PATH} in a connection string is expanded to the application directory, which is convenient for file-based databases.

Query and update

// Scalars, readers and DataSets; {0}, {1}, … become real parameters, never string concatenation.
var total = DbConvert.ToInt32(ScalarUtility.GetScalar("SELECT COUNT(*) FROM Customer"));

using var reader = DataReaderUtility.GetDataReader(
    "SELECT Id, Name FROM Customer WHERE CountryId = {0}", countryId);

var orders = DataSetUtility.GetDataSet("SELECT * FROM Orders WHERE Date >= {0}", since);

var affected = SetUtility.SetData("DELETE FROM Cart WHERE SessionId = {0}", sessionId);
DataBase.BeginTransaction();
try
{
    SetUtility.SetData("UPDATE Account SET Balance = Balance - {0} WHERE Id = {1}", amount, from);
    SetUtility.SetData("UPDATE Account SET Balance = Balance + {0} WHERE Id = {1}", amount, to);
    DataBase.CommitTransaction();
}
catch
{
    DataBase.RollBackTransaction();
    throw;
}

Build statements from row state

CommandBuilder turns "old values / new values" into parameterised INSERT, UPDATE, DELETE and SELECT statements — the shape a grid or a data-bound form already has. It honours optimistic locking, identity columns, per-column save expressions and value generators.

string? sql = null;
DbParameter?[]? parameters = null;

CommandBuilder.GetSqlRowUpdate(
    "Customer", newValues, oldValues,
    useOptimisticLocking: false,
    ref sql, ref parameters,
    primaryKeys: new[] { "Id" },
    visualizations: new Dictionary<string, bool> { ["Id"] = true, ["Name"] = true },
    decodes: new Dictionary<string, string?>(),
    isCounterField: new Dictionary<string, bool> { ["Id"] = true, ["Name"] = false });

// UPDATE Customer SET Name = @NewName WHERE Id = @Id

TableUtil builds the paging predicates that go with it — MakeWhereFw, MakeWhereBw, MakeWhereStand walk a composite key forwards, backwards and from the current row.

Schema

string?[]? fields = null; Type?[]? types = null; string?[]? keys = null;
int[]? sizes = null; string?[]? unique = null;

SchemaUtility.GetSchema("Customer", ref fields, ref types, ref keys, ref sizes, ref unique);

SchemaUtility.CheckTableExistance("Customer");
SchemaUtility.CheckPrimaryKeyExistance("Customer");

var create = DatabaseTypes.BuildCreateStatement("Customer", new List<TableField>
{
    new() { FieldName = "Id",   FieldType = DatabaseTypes.IntType },
    new() { FieldName = "Name", FieldType = DatabaseTypes.StringType, StringSize = 50, AllowNull = true }
});

Schema lookups are cached in SchemaUtility.DbCache; clear it after a DDL change.

What else is in the box

Namespace Contents
DataLibraryStarb.DataAccess DataBase, CommandBuilder, SchemaUtility, DbSchema, TableUtil, DataReaderUtility, DataSetUtility, ScalarUtility, SetUtility, ParameterUtility, TransactionUtility, DbTypeMapper, DatabaseTypes
DataLibraryStarb.Utility DbConvert (never-throwing conversions), StringHelper, ArrayHelper, StringResource
DataLibraryStarb.DynamicCompilation.Reflection ReflectionHelper, ReflectionExecuter, TypeGetter — enumerate, read, write and invoke members including non-public ones
DataLibraryStarb.Logging Dumper, LoggerHelper — XML logs of entries and of the current data-reader row
DataLibraryStarb.HelperClasses DbSession, PathHelper, ResourceHelper, ResourcesHelper
DataLibraryStarb.Web HttpContextHelper and its interfaces

Running inside a web application

The library never references ASP.NET. HttpContextHelper.Current takes any implementation of IHttpContext; set it once at start-up and connections, transactions, session values and DataSet caches move from static fields to per-request state:

HttpContextHelper.Current = new MyAspNetHttpContext(HttpContext.Current);

Leave it null in desktop and console applications.

Notes

  • Configuration lives in static state, so it is process-wide: set the provider once at start-up.
  • DbConvert returns a default (0, false, DateTime.MinValue) instead of throwing, which suits reading loosely typed database values.
  • DataBase.DbError holds the last provider exception after a failed call.

License

Copyright (c) Piero Viano. All rights reserved. — Librerie Starbook

Product Compatible and additional computed target framework versions.
.NET net10.0-windows7.0 is compatible. 
.NET Framework net462 is compatible.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (3)

Showing the top 3 NuGet packages that depend on Starb.DataLibrary:

Package Downloads
Starb.WebLibrary

Web Library Fundamental Class

Starb.ExcelInterop

Package Description

Starb.PaccoLibrary

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.0.26263 42 9/20/2026
2.0.0 441 3/31/2025