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.
- Easy-to-use connection management
- Execute SQL commands with or without parameters
- Retrieve data as a list of objects
- Supports .NET 8.0
You can install the SRT.SqlClient package via NuGet:
dotnet add package SRT.SqlClient
Before using the library, set the connection string:
using SRT.SqlClient;
DbConnection.ConnectionString = "your-connection-string";
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"]);
}
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"]);
}
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);
}
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.
- SR Tamim - Author
This project is licensed under the MIT License - see the LICENSE file for details.