SRT.SqlClient
0.0.2
dotnet add package SRT.SqlClient --version 0.0.2
NuGet\Install-Package SRT.SqlClient -Version 0.0.2
<PackageReference Include="SRT.SqlClient" Version="0.0.2" />
paket add SRT.SqlClient --version 0.0.2
#r "nuget: SRT.SqlClient, 0.0.2"
// Install SRT.SqlClient as a Cake Addin #addin nuget:?package=SRT.SqlClient&version=0.0.2 // Install SRT.SqlClient as a Cake Tool #tool nuget:?package=SRT.SqlClient&version=0.0.2
SRT.SqlClient
Description
SRT.SqlClient is a simple SQL client library designed to make database transactions easier. It provides a straightforward API for connecting to a SQL database, executing commands, and reading data.
Features
- Easy-to-use connection management
- Execute SQL commands with or without parameters
- Retrieve data as a list of objects
- Supports .NET 8.0
Installation
You can install the SRT.SqlClient package via NuGet:
dotnet add package SRT.SqlClient
Usage
Setting the Connection String
Before using the library, set the connection string:
using SRT.SqlClient;
DbConnection.ConnectionString = "your-connection-string";
Executing a Command
To execute a SQL command and read data:
using SRT.SqlClient;
using Microsoft.Data.SqlClient;
using System.Collections.Generic;
var query = "SELECT * FROM Users";
using var reader = new DbReader();
var data = reader.ExecuteCommand(query);
while (data.Read())
{
Console.WriteLine(data["Username"]);
}
Executing a Command with Parameters
To execute a SQL command with parameters:
using SRT.SqlClient;
using Microsoft.Data.SqlClient;
using System.Collections.Generic;
var query = "SELECT * FROM Users WHERE Age > @Age";
var parameters = new List<SqlParameter>
{
new SqlParameter("@Age", 18)
};
using var reader = new DbReader();
var data = reader.ExecuteCommand(query, parameters);
while (data.Read())
{
Console.WriteLine(data["Username"]);
}
Retrieving Data as a List of Objects
To retrieve data as a list of objects:
using SRT.SqlClient;
using Microsoft.Data.SqlClient;
using System.Collections.Generic;
var query = "SELECT * FROM Users";
using var reader = new DbReader();
var users = reader.GetDataList<User>(query);
foreach (var user in users)
{
Console.WriteLine(user.Username);
}
Contributing
We welcome contributions to SRT.SqlClient! To contribute:
- Fork the repository.
- Create a new branch (git checkout -b feature-branch).
- Make your changes.
- Commit your changes (git commit -am 'Add new feature').
- Push to the branch (git push origin feature-branch).
- Create a new Pull Request.
Contributors
- SR Tamim - Author
License
This project is licensed under the MIT License - see the LICENSE file for details.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. 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. |
-
net8.0
- Microsoft.Data.SqlClient (>= 5.2.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.