https://github.com/ntdls/ntdls.sqlmanagedconnectivity
Wraps a native SQL Server connection, allows for easy field/value enumeration and manages cleanup.
https://github.com/ntdls/ntdls.sqlmanagedconnectivity
dapper disposable managed-connectivity sqlserver
Last synced: 9 months ago
JSON representation
Wraps a native SQL Server connection, allows for easy field/value enumeration and manages cleanup.
- Host: GitHub
- URL: https://github.com/ntdls/ntdls.sqlmanagedconnectivity
- Owner: NTDLS
- License: mit
- Created: 2023-12-05T01:17:14.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-12-31T12:01:05.000Z (about 1 year ago)
- Last Synced: 2025-03-27T21:22:55.190Z (10 months ago)
- Topics: dapper, disposable, managed-connectivity, sqlserver
- Language: C#
- Homepage:
- Size: 55.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# NTDLS.SqlManagedConnectivity
📦 Be sure to check out the NuGet package: https://www.nuget.org/packages/NTDLS.SqlManagedConnectivity
Wraps a native SQL Server connection, allows for easy field/value enumeration and manages cleanup.
This library is a replacement for native-style SQL Server access, if you are looking something more POCO/Dapper,
then check out the https://github.com/NTDLS/NTDLS.SqlServerDapperWrapper.
>**Simple example:**
>
>In this example we are opening a connection to the local SQL Server (".") and the database ("Dummyload"), then selecting all rows and columns from the table [Test].
> This demonstrates how we can enumerate the fields and their types as well as the rows and their values with several options for conversion.
```csharp
using (var connection = new SqlManagedConnection(".", "Dummyload"))
{
using (var reader = connection.ExecuteQuery("SELECT * FROM Test WHERE Account <> @Account", new { Account = 4104 }))
{
//Loop through all fields:
foreach (var field in reader.Fields)
{
Console.WriteLine($"Field: '{field.Name}', Data Type: '{field.DataTypeName}', Type: '{field.Type.Name}'");
}
//Loop though all rows:
foreach (var row in reader)
{
//Loop though all values in the row:
foreach (var value in row)
{
Console.WriteLine($"{value.Field.Name} -> '{value.As()?.Trim()}'");
}
var doublePercentTaxable1 = row.Value("PercentTaxable");
var decimalPercentTaxable1 = row.Value("OriginalAmount");
var stringPercentTaxable1 = row.Value("OriginalAmount");
var intPercentTaxable1 = row.Value("OriginalAmount");
}
}
}
```
## License
[Apache-2.0](https://choosealicense.com/licenses/apache-2.0/)