The purpose of this library is the CRUD operations on the mssql server and also to work with a clean architecture. This library was developed with .NET standard.
Install-Package TStack.ADO -Version 1.0.1
dotnet add package TStack.ADO --version 1.0.1
<PackageReference Include="TStack.ADO" Version="1.0.1" />
paket add TStack.ADO --version 1.0.1
Before usage test project create manually database table like on picture
Inherit the ADOConnection class to the new class you are creating and set up the database connection.
public class TestConnection : ADOConnection
{
public TestConnection() : base(@"Server=.\SQLEXPRESS;Database=TESTDB;Trusted_Connection=True;")
{
}
}
ADOManager is an abstract class, so it must be inherited to your new class, in which case all methods can be used
public class SQLManager : ADOManager
{
public SQLManager(TestConnection connection) : base(connection)
{
}
}
That's it, ready to use.
For use methods first learn what is parameters and features, lets look.
This parameter is the reference type string, if the entered query is stored procedure, the CommandType parameter should be selected as "StoredProcedure", otherwise "Text"
This parameter is the reference type enum and have two choice
- Text
- StoredProcedure
This parameter is reference type List of Parameter class and for usage has two parameter "key" (string,not nullable), "value" (object, not nullable) Example Usage :
List<Parameter> parameters = new List<Parameter>();
parameters.Add("Name", "Ferhat");
Note : The @ character is not required in the entered key parameter. No problem if entered.
parameters.Add("Name", "Ferhat"); Allowed
parameters.Add("@Name", "Ferhat"); Allowed
This function returns a generic variable type, the typed query contains a single row and must contain a single column.
int response = _adomanager.ExecuteScalar<int>("SELECT count(*) from companies",CommandType.Text,null);
This function has no return type. Runs a typed query.
_adomanager.Execute("TRUNCATE TABLE companies",CommandType.Text,null);
This function returns datatable, Runs a typed query, but must contains single query.
DataTable datatable = _adomanager.GetDataTable("SELECT * FROM companies",CommandType.Text,null);
This function returns dataset, Runs a typed queries, contains can multiple queries.
DataSet dataset = _adomanager.GetDataTable(@"
SELECT * FROM companies;
SELECT * FROM employees;
",CommandType.Text,null);
Ferhat Candaş - Software Developer
- Mail : [email protected]
- LinkedIn : https://www.linkedin.com/in/ferhatcandas