YGADO 1.6.0

dotnet add package YGADO --version 1.6.0                
NuGet\Install-Package YGADO -Version 1.6.0                
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="YGADO" Version="1.6.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add YGADO --version 1.6.0                
#r "nuget: YGADO, 1.6.0"                
#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.
// Install YGADO as a Cake Addin
#addin nuget:?package=YGADO&version=1.6.0

// Install YGADO as a Cake Tool
#tool nuget:?package=YGADO&version=1.6.0                

YGADO

A simple ADO to execute a stored procedure and return DataSet or Dictionary of output parameters

Installation

Include this package in the project file

Use code inside a Try catch block. For brevity, there is no try catch block in GetDataSet

Usage

//Oracle example: 
string orclconnStr = "Data Source=;User Id=;Password=;";

IOracleDBTool orcl = new OracleDBTool(orclconnStr);

int envlientId = 534;
string sql1 = $"SELECT * FROM CLIENT where ENVCLIENTID = {envlientId}";
string sql2 = $"SELECT * FROM AUTHORIZATION WHERE ENVCLIENTID = {envlientId}";

using (DataSet ds = orcl.GetDataSet(new string[] { sql1, sql2 }))
{
    foreach (DataTable dt in ds.Tables)
    {
        Console.WriteLine(dt.Rows.Count);
        string contents = JsonConvert.SerializeObject(dt, Formatting.Indented);
        Console.WriteLine(contents);
    }
}


// SQL Server example: 
IDBSPTool db = new DBSPTool(connStr);

Dictionary<string, object> inputParms = new Dictionary<string, object>()
{
    {"Status", "Complete" }
};

Dictionary<string, SqlDbType> outputParms = new Dictionary<string, SqlDbType>()
{
    {"ExecutedDate", SqlDbType.DateTime },
    {"ExecuteStatus", SqlDbType.Bit }
};

var result = db.GetDataSet("USPGetEmplRecs", inputParms, outputParms);

Console.WriteLine(JsonConvert.SerializeObject(result, Formatting.Indented));

//or

IDBSPTool db = new DBSPTool(connStr);
var result = db.ExecSP("USPTest");

string resultStatus = JsonConvert.SerializeObject(result);

// OR

var result = await db.ExecSPAsync("USPTest");

string resultStatus = result.Item2;

// if using IOC container:

  builder.Services.AddScoped<IDBSPTool, DBSPTool>(_ => new DBSPTool(configuration.GetConnectionString("AppDbContext")));

  @inject IDBSPTool _idbsp

   var result = await db.ExecSPAsync("USPTest");

Examples

Test project is provided in the solution to illustrate how to invoke SP and get DataSet and output dictionary back

Interfaces:

  public interface IDBSPTool
    {
        Dictionary<string, object> ExecSP(SqlConnection sqlConn, string spName, Dictionary<string, object> inputParms = null, Dictionary<string, SqlDbType> outputParms = null, bool closeConnectionAfter = false);
        string ExecSP(string sqlText);
        Dictionary<string, object> ExecSP(string spName, Dictionary<string, object> inputParms = null, Dictionary<string, SqlDbType> outputParms = null);
        Task<Tuple<Dictionary<string, object>, string, Exception?>> ExecSPAsync(string spName, Dictionary<string, object> inputParms = null, Dictionary<string, SqlDbType> outputParms = null);
        DataSet GetDataSet(string sqlQuery, bool isQueryText);
        Tuple<DataSet, Dictionary<string, object>, Exception> GetDataSet(string spName, Dictionary<string, object> inputParms = null, Dictionary<string, SqlDbType> outputParms = null);
    }


      public interface IOracleDBTool
        {
            DataTable GetDataTable(string sqlQuery);
            DataSet GetDataSet(string[] sqlQueries);
        }

Output:

The output is a Tuple<DataSet,Dictionary<string, object>, Exception> for GetDataSet with SP or Dictionary for ExecSP.

Dependencies

Microsoft.Data.SqlClient

Contributing

Any new ideas on how to enhance this class without adding much complexity, please adhere to SOLID principle

License

This project is licensed under the MIT License(LICENSE).

Product 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.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
1.6.0 80 1/2/2025
1.5.0 83 12/27/2024
1.4.1 86 12/10/2024
1.4.0 103 11/16/2024
1.3.3 102 10/9/2024
1.3.2 129 6/17/2024
1.3.1 119 6/17/2024
1.3.0 117 6/17/2024
1.2.0 127 6/1/2024
1.1.0 118 6/1/2024
1.0.0 125 5/31/2024

Updated to .net 8 as .net 6 is no longer supported