WiseProgress.Data 2026.5.16.1

Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
dotnet add package WiseProgress.Data --version 2026.5.16.1
                    
NuGet\Install-Package WiseProgress.Data -Version 2026.5.16.1
                    
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="WiseProgress.Data" Version="2026.5.16.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="WiseProgress.Data" Version="2026.5.16.1" />
                    
Directory.Packages.props
<PackageReference Include="WiseProgress.Data" />
                    
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 WiseProgress.Data --version 2026.5.16.1
                    
#r "nuget: WiseProgress.Data, 2026.5.16.1"
                    
#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 WiseProgress.Data@2026.5.16.1
                    
#: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=WiseProgress.Data&version=2026.5.16.1
                    
Install as a Cake Addin
#tool nuget:?package=WiseProgress.Data&version=2026.5.16.1
                    
Install as a Cake Tool

WiseProgress.Data

A data access library targeting .NET Standard 2.0 (compatible with .NET Framework 4.8 and .NET 8).
Namespace root: WiseProgress.Data
SQL provider: Microsoft.Data.SqlClient


Table of Contents

  1. ConnectionInfo
  2. SqlConnection
  3. QueryBuilder(Of T)
  4. CommandBuilder
  5. CommandBuilderList
  6. DatabaseIdentityAttribute
  7. SqlManagement.Server
  8. DatabaseComparer

ConnectionInfo

Namespace: WiseProgress.Data.SqlConnection
Implements: IDisposable

Holds the connection parameters used to build a SQL Server connection string.

Properties

Property Type Default Description
ServerName String SQL Server host name or IP
Database String Initial database / catalog
SqlUser String SQL Server login username
SqlPassword String SQL Server login password
WindowsAuthentication Boolean False Use Windows (Integrated) authentication instead of SQL login
UseConnectedEnvironment Boolean False When True, the connection stays open between calls (required for transactions)
ConnectTimeout Integer 15 Seconds to wait when opening the connection
CommandTimeout Integer 60 Seconds to wait for a command to execute
TrustServerCertificate Boolean True Bypasses SSL certificate validation

Constructors

New()
New(ServerName, Database, SqlUser, SqlPassword, WindowsAuthentication)

Example

Dim info As New ConnectionInfo(".", "MyDB", "sa", "pass", False)
info.UseConnectedEnvironment = True   ' keep connection open (needed for transactions)

SqlConnection

Namespace: WiseProgress.Data.SqlConnection
Implements: IDisposable

The main database access class. Wraps Microsoft.Data.SqlClient.SqlConnection and exposes synchronous and asynchronous query, scalar, reader, and transaction methods.

Properties

Property Type Description
ConnectionInfo ConnectionInfo Connection parameters
ConnectionString String (ReadOnly) Built connection string derived from ConnectionInfo
ConnectionOpened Boolean (ReadOnly) True if the underlying connection is currently open
MainSqlConnection SqlConnection (ReadOnly) The raw Microsoft.Data.SqlClient.SqlConnection. Opens if not already open
CurrenctSqlTransaction SqlTransaction The active transaction, if any

Constructors

New()
New(ServerName, Database, SqlUser, SqlPassword, WindowsAuthentication)

Connection Methods

Method Signature Description
ConnectToServer () As Boolean Opens the connection if not already open
ConnectToServerAsync () As Task(Of Boolean) Async version of ConnectToServer
Close () Closes the connection
SwitchToDatabase (DatabaseName As String) Changes the active database (USE DatabaseName)

Transaction Methods

Requires ConnectionInfo.UseConnectedEnvironment = True

Method Signature Description
BeginTrans () As SqlTransaction Starts a new transaction. Throws if one is already active
CommitTrans () As Boolean Commits and disposes the active transaction
CommitTrans (Transaction As SqlTransaction) As Boolean Commits and disposes a specific transaction
RollBack () Rolls back and disposes the active transaction
RollBack (Transaction As SqlTransaction) Rolls back and disposes a specific transaction

Execute Methods

Method Signature Returns Description
ExecuteNonQuery (Query As String) Integer Runs a non-SELECT statement. Returns rows affected
ExecuteNonQueryAsync (Query As String) Task(Of Integer) Async version
ExecuteQuery (Query As String) DataTable Runs a SELECT and returns a DataTable
ExecuteQueryAsync (Query As String) Task(Of DataTable) Async version
ExecuteQuery(Of T) (Query As String) List(Of T) Runs a SELECT and maps rows to a typed list by column name ↔ property name
ExecuteQuery(Of T) (tableOrView, whereCondition, orderBy) List(Of T) Builds and runs a SELECT * query with optional WHERE / ORDER BY
ExecuteQueryAsync(Of T) (Query As String) Task(Of List(Of T)) Async typed query
ExecuteQueryBinding(Of T) (Query As String) BindingList(Of T) Returns a BindingList for data binding scenarios
ExecuteQueryOneRow (Query As String) DataRow Returns the first row or Nothing
ExecuteQueryOneRowAsync (Query As String) Task(Of DataRow) Async version
ExecuteQueryOneRow(Of T) (Query As String) T Returns the first row mapped to T, or a new empty T
ExecuteQueryOneRowAsync(Of T) (Query As String) Task(Of T) Async version
ExecuteQueryOneRow(Of T) (query, ByRef item As T) Sets item to the first matching row
ExecuteSelectQuery (tableOrView, whereCondition, orderBy) DataTable Builds SELECT * FROM table [WHERE] [ORDER BY] and returns a DataTable
ExecuteSelectQuery(Of T) (whereCondition, orderBy) DataTable Same but derives table name from GetType(T).Name
ExecuteScalar (Query As String) Object Returns the first column of the first row
ExecuteReader (Query As String) SqlDataReader Returns an open SqlDataReader (uses CommandBehavior.CloseConnection)

Scalar / Utility Methods

Method Signature Returns Description
GetValue (Query As String) Double Returns the first cell as Double, or 0 if no rows
GetStringValue (Query As String) String Returns the first cell as String, or "" if no rows
GetGuidValue (Query As String) Guid Returns the first cell as Guid, or Guid.Empty if no rows
GetObjectValue (Query As String) Object Returns the first cell as Object, or Nothing if no rows
GetNewNumber (TableName, FieldName, Condition, DefaultNumber) Long Returns MAX(FieldName) + 1. Useful for sequential numbering
FieldValueExists (TableName, FieldName, value, Condition) Boolean Returns True if any row matches the value in the field
FieldValueExists (TableName, FieldName, value, Condition, condition2, condition3) Boolean Same with up to three AND conditions
IsIdentityField (tableName, columnName) Boolean Returns True if the column is a SQL IDENTITY column
DBString (InVal As String) String Escapes single quotes for safe SQL embedding

Example

Dim conn As New SqlConnection.SqlConnection(".", "MyDB", "sa", "pass", False)

' Simple query → DataTable
Dim dt = conn.ExecuteQuery("SELECT * FROM Products")

' Typed query → List(Of T)
Dim products = conn.ExecuteQuery(Of Product)("SELECT * FROM Products WHERE Active = 1")

' Single value
Dim total As Double = conn.GetValue("SELECT SUM(Amount) FROM Orders")

' Insert / Update
conn.ExecuteNonQuery("INSERT INTO Log (Msg) VALUES (N'Started')")

' Transaction
conn.ConnectionInfo.UseConnectedEnvironment = True
Dim tx = conn.BeginTrans()
Try
	conn.ExecuteNonQuery("UPDATE Stock SET Qty = Qty - 1 WHERE Id = 5")
	conn.CommitTrans(tx)
Catch
	conn.RollBack(tx)
End Try

QueryBuilder(Of T)

Namespace: (root)

A fluent, strongly-typed SQL query builder that generates and executes SELECT statements.
The table name is derived from GetType(T).Name.

Constructor

New(Connection As SqlConnection.SqlConnection)

WHERE Clauses (chainable)

Method Description
Where(propExpr, op, value) Adds [Column] {op} {value} — op examples: "=", ">", "<>"
WhereIn(propExpr, values) Adds [Column] IN (v1, v2, ...)
WhereNotIn(propExpr, values) Adds [Column] NOT IN (v1, v2, ...)
WhereContains(propExpr, value) Adds [Column] LIKE '%value%'
WhereNotContains(propExpr, value) Adds [Column] NOT LIKE '%value%'
WhereStartsWith(propExpr, value) Adds [Column] LIKE 'value%'
WhereEndsWith(propExpr, value) Adds [Column] LIKE '%value'

All conditions are combined with AND.

ORDER BY Clauses (chainable)

Method Description
OrderByAscending(propExpr) Sets primary ORDER BY [Column] ASC
OrderByDescending(propExpr) Sets primary ORDER BY [Column] DESC
ThenByAscending(propExpr) Adds secondary [Column] ASC
ThenByDescending(propExpr) Adds secondary [Column] DESC

Execution Methods

Method Returns Description
ToSql() String Returns the generated SQL string without executing it
ToList() List(Of T) Executes and returns all matching rows
FirstOrDefault() T Returns the first row, or Nothing
SingleOrDefault() T Returns exactly one row; throws if more than one match
Any() Boolean Returns True if at least one row matches
Count() Integer Returns the count of matching rows

Example

Dim conn As New SqlConnection.SqlConnection(info)

Dim results = New QueryBuilder(Of Product)(conn) _
	.Where(Function(p) p.CategoryId, "=", 3) _
	.WhereContains(Function(p) p.Name, "chair") _
	.OrderByAscending(Function(p) p.Name) _
	.ToList()

Dim sql = New QueryBuilder(Of Order)(conn) _
	.Where(Function(o) o.Date, ">=", #1/1/2024#) _
	.WhereIn(Function(o) o.StatusId, {1, 2, 3}) _
	.ToSql()
' → SELECT * FROM Order WHERE Date >= '2024-01-01 00:00:00' AND StatusId IN (1, 2, 3)

CommandBuilder

Namespace: WiseProgress.Data.CommandBuilder
Implements: IDisposable

Builds parameterized INSERT, UPDATE, and SELECT SQL command strings from field/value pairs or from a class instance.

Properties

Property Type Description
TableName String Target table name. Auto-set from T's type name when using AddValuesOfClass

Constructors

New()
New(Table As String)

enFieldType Enum

Value SQL representation
Number Numeric literal (0, 1.5, etc.)
Text N'value' (Unicode string)
SearchText LIKE '%value%'
Date 'yyyy-MM-dd'
DateTime 'yyyy-MM-dd HH:mm:ss'
Time 'HH:mm:ss' (from TimeSpan)
Guid 'xxxxxxxx-xxxx-…' or NULL
Bit 1 or 0

SetValue / AddValue Methods

Method Signature Description
SetValue (FieldName, Value, FieldType As enFieldType) Adds or updates a field with explicit type
SetValue (FieldName, Value As Object) Adds or updates a field as Text type
AddValue (FieldName, arg, Optional DataType As String) Auto-detects type from arg.GetType.Name and formats accordingly

Class-based Population

Method Signature Description
AddValuesOfClass(Of T) (obj As T) Reads all writable properties of obj and calls AddValue for each. Skips [DatabaseIdentity] properties. Sets TableName from type name if empty
AddValuesOfClass(Of T) (obj As List(Of T)) Calls AddValuesOfClass for each item in the list

Command Generation Methods

Method Signature Returns Description
GetInsertCommand () String INSERT INTO TableName ([F1],[F2]) VALUES (v1,v2)
GetInsertCommand(Of T) (obj As List(Of T)) String Generates multiple INSERT statements joined by ;
GetUpdateCommand (UpdateCondition As String) String UPDATE TableName SET [F1]=v1,… UpdateCondition. Include WHERE in the condition
GetSelectCommand (FieldsToReturn As String) String SELECT fields FROM TableName WHERE [F1]=v1 AND …
GetWhereCondition () String Returns only the WHERE body (no WHERE keyword). SearchText fields use LIKE

Example

' Manual field-by-field
Using cb As New CommandBuilder("Products")
	cb.SetValue("Name", "Widget", CommandBuilder.enFieldType.Text)
	cb.SetValue("Price", 9.99, CommandBuilder.enFieldType.Number)
	cb.SetValue("CreatedAt", Now, CommandBuilder.enFieldType.DateTime)
	Dim sql = cb.GetInsertCommand()
	' → INSERT INTO Products ([Name],[Price],[CreatedAt]) VALUES (N'Widget',9.99,'2024-03-15 10:30:00')
	conn.ExecuteNonQuery(sql)
End Using

' From class instance
Dim p As New Product With {.Name = "Gadget", .Price = 19.99}
Using cb As New CommandBuilder()
	cb.AddValuesOfClass(p)
	conn.ExecuteNonQuery(cb.GetInsertCommand())
End Using

CommandBuilderList

Namespace: WiseProgress.Data.CommandBuilder
Implements: IDisposable

A container that accumulates SQL command strings and executes them as a single batch.

Methods

Method Signature Description
AddCommand (Command As String) Appends a SQL statement to the list
CommandsForExecution () As String Returns all commands joined by ; for batch execution
Clear () Removes all stored commands

Example

Using list As New CommandBuilderList()
	list.AddCommand(cb1.GetInsertCommand())
	list.AddCommand(cb2.GetUpdateCommand("WHERE Id = 5"))
	conn.ExecuteNonQuery(list.CommandsForExecution())
End Using

DatabaseIdentityAttribute

Namespace: WiseProgress.Data.Annotations
Inherits: Attribute

Marks a property as a SQL Server IDENTITY column.
CommandBuilder.AddValuesOfClass automatically skips decorated properties so they are never included in INSERT or UPDATE statements.

Usage

Public Class Product
	<DatabaseIdentity>
	Public Property Id As Integer       ' IDENTITY — excluded from INSERT/UPDATE

	Public Property Name As String      ' Normal column — included
	Public Property Price As Decimal    ' Normal column — included
End Class

SqlManagement.Server

Namespace: WiseProgress.Data.SqlManagement

Exposes SQL Server instance metadata via SERVERPROPERTY.

Constructor

New(ServerConnectionInformation As ConnectionInfo)

Properties (all ReadOnly)

Property Type Description
VersionNumber String Full version string, e.g. "16.0.1000.6"
Version SqlServerVersion Enum value mapping the major version number
Collation String Server collation name
Edition String Server edition (e.g. "Developer Edition")
EngineEdition String Engine edition identifier
InstanceName String Named instance name
IsClustered Boolean Whether the instance is in a failover cluster
IsFullTextInstalled Boolean Whether Full-Text Search is installed
IsIntegratedSecurityOnly Boolean Whether only Windows auth is allowed
IsSingleUser Boolean Whether the server is in single-user mode
LicenseType String License type string

SqlServerVersion Enum

Value SQL Server Year
SqlServer7 SQL Server 7
SqlServer2000 SQL Server 2000
SqlServer2005 SQL Server 2005
SqlServer2008 SQL Server 2008
SqlServer2012 SQL Server 2012
SqlServer2014 SQL Server 2014
SqlServer2016 SQL Server 2016
SqlServer2017 SQL Server 2017
SqlServer2019 SQL Server 2019
SqlServer2021 SQL Server 2021+

Example

Dim srv As New SqlManagement.Server(info)
Console.WriteLine(srv.VersionNumber)   ' "16.0.1000.6"
Console.WriteLine(srv.Version)         ' SqlServer2021
Console.WriteLine(srv.Edition)         ' "Developer Edition (64-bit)"

DatabaseComparer

Namespace: (root)

Compares two SQL Server databases and synchronizes the destination to match the source schema (tables, columns, views, functions, stored procedures).

Constructor

New(sourceConnectionString As String, destinationConnectionString As String)

Methods

Method Description
CompareAndUpdate() Compares source and destination. Creates missing tables/views/functions/procedures in destination. Adds missing columns to existing tables

What it compares

Object type Missing in destination Column mismatch
Tables Creates table Adds missing columns
Views Creates view Compares columns
Functions Creates function
Stored Procedures Creates procedure

Example

Dim comparer As New DatabaseComparer(
	"Server=source;Database=MyDB_Dev;Integrated Security=True",
	"Server=dest;Database=MyDB_Prod;Integrated Security=True")

comparer.CompareAndUpdate()
' Missing tables/columns/views/functions/procs in Prod are created from Dev

Type Mapping (ExecuteQuery(Of T))

When mapping DataTable rows or SqlDataReader to typed objects, column names are matched to property names case-insensitively. The following conversions are handled automatically:

SQL Type .NET Property Type Conversion
float / real Decimal Convert.ToDecimal
decimal / money Double Convert.ToDouble
int Integer Convert.ToInt32
bigint Long Convert.ToInt64
smallint Short Convert.ToInt16
tinyint Byte Convert.ToByte
bit Boolean direct
uniqueidentifier Guid direct
nvarchar / varchar String direct
datetime / date DateTime direct
integer enum column Enum Enum.ToObject
string enum column Enum Enum.Parse

NULL database values are silently skipped — the property retains its default value.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

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
2026.5.21.1 194,077 5/21/2026
2026.5.16.1 72,168 5/16/2026
2026.4.27.1 205,436 4/27/2026
2026.4.19.1 109,403 4/18/2026
2026.3.20.1 220,385 3/20/2026
2026.3.1.1 248,238 3/1/2026
2026.2.18.1 128,240 2/18/2026
2026.2.15.2 40,663 2/15/2026
2026.2.15.1 3,562 2/15/2026
2026.2.14.2 11,136 2/14/2026
2026.2.14.1 123 2/14/2026
2026.2.7.1 85,256 2/7/2026
2026.1.20.1 238,247 1/20/2026
2026.1.17.1 34,106 1/17/2026
2025.8.28.1 1,829,193 8/28/2025
2025.3.27.1 4,425,196 3/27/2025
2025.3.25.1 578 3/25/2025
2025.3.24.1 609 3/24/2025
2025.3.23.1 361 3/23/2025
2025.3.20.1 9,561 3/20/2025
Loading failed