ASql 1.0.0.1
.NET 8.0
This package targets .NET 8.0. The package is compatible with this framework or higher.
.NET Framework 4.8
This package targets .NET Framework 4.8. The package is compatible with this framework or higher.
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package ASql --version 1.0.0.1
NuGet\Install-Package ASql -Version 1.0.0.1
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="ASql" Version="1.0.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ASql --version 1.0.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: ASql, 1.0.0.1"
#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 ASql as a Cake Addin #addin nuget:?package=ASql&version=1.0.0.1 // Install ASql as a Cake Tool #tool nuget:?package=ASql&version=1.0.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
ASql
C# Library that let use multiple types of databases with same code
The supported databases are SqlServer and Oracle
You only have to declare wich type of database would like you use and use the classe in the same way of sql or oracle client.
Here you can find examples :
Example 1 Basic query
ASqlManager.DataBaseType = ASqlManager.DBType.Oracle;
using (ASqlConnection conn = new ASqlConnection(ConnectionString))
{
int i = 0;
conn.Open();
ASqlCommand cmd = new ASqlCommand(sql, conn);
using (DbDataReader read = cmd.ExecuteReader())
{
while (read.Read())
{
i = read.GetInt32(read.GetOrdinal("nvalue"));
}
}
}
Example 2 Query With Parameters
public void InsertRow(ASqlManager.DBType dBType, string ConnectionString, string sql)
{
Dictionary<string, object> d = new Dictionary<string, object>();
for (int i = 1; i < 2; i++)
{
d.Add("firstname", "first" + i);
d.Add("lastname", "last" + i);
d.Add("age", i);
d.Add("value", i * 1000);
d.Add("birthday", DateTime.Now);
d.Add("hourly", 123.456);
d.Add("localtime", new DateTimeOffset(2021, 4, 14, 01, 02, 03, new TimeSpan(7, 0, 0)));
d.Add("picture", _FileBytes);
d.Add("guid", Guid.NewGuid());
d.Add("active", (i % 2 > 0));
}
ASqlManager.DataBaseType = dBType;
using (ASqlConnection conn = new ASqlConnection(ConnectionString))
{
int i = 0;
conn.Open();
ASqlCommand cmd = new ASqlCommand(sql, conn);
List<ASqlParameter> apc = GetParametersFromkeyValuePairs(d);
foreach (ASqlParameter param in apc)
{
cmd.aSqlParameters.Add(param);
}
i = cmd.ExecuteNonQuery();
Assert.AreEqual(1, i);
}
}
internal List<ASqlParameter> GetParametersFromkeyValuePairs(Dictionary<string, object> keyValuePairs)
{
string vals = "";
List<ASqlParameter> prm = new List<ASqlParameter>();
foreach (KeyValuePair<string, object> currKvp in keyValuePairs)
{
if (currKvp.Value is DateTime
|| currKvp.Value is DateTime?)
{
ASqlParameter para = new ASqlParameter();
para.ParameterName = ":" + currKvp.Key;
para.Direction = ParameterDirection.Input;
para.Value = currKvp.Value;
prm.Add(para);
}
else if (currKvp.Value is DateTimeOffset
|| currKvp.Value is DateTimeOffset?)
{
ASqlParameter para = new ASqlParameter();
para.ParameterName = ":" + currKvp.Key;
para.Direction = ParameterDirection.Input;
para.Value = currKvp.Value;
prm.Add(para);
}
else if (currKvp.Value is int
|| currKvp.Value is long
|| currKvp.Value is decimal)
{
ASqlParameter para = new ASqlParameter();
para.ParameterName = ":" + currKvp.Key;
para.Direction = ParameterDirection.Input;
para.Value = currKvp.Value;
prm.Add(para);
}
else if (currKvp.Value is bool)
{
string val = ((bool)currKvp.Value ? "1" : "0");
ASqlParameter para = new ASqlParameter();
para.ParameterName = ":" + currKvp.Key;
para.Direction = ParameterDirection.Input;
para.Value = val;
prm.Add(para);
}
else if (currKvp.Value is byte[])
{
ASqlParameter para = new ASqlParameter();
para.ParameterName = ":" + currKvp.Key;
para.Direction = ParameterDirection.Input;
para.Value = currKvp.Value;
prm.Add(para);
}
else if (currKvp.Value is string)
{
ASqlParameter para = new ASqlParameter();
para.ParameterName = ":" + currKvp.Key;
para.Direction = ParameterDirection.Input;
para.Value = currKvp.Value;
prm.Add(para);
}
else if (currKvp.Value is Guid)
{
ASqlParameter para = new ASqlParameter();
para.ParameterName = ":" + currKvp.Key;
para.Direction = ParameterDirection.Input;
para.Value = currKvp.Value.ToString();
prm.Add(para);
}
else
{
ASqlParameter para = new ASqlParameter();
para.ParameterName = ":" + currKvp.Key;
para.Direction = ParameterDirection.Input;
para.Value = currKvp.Value;
prm.Add(para);
}
}
return prm;
}
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. |
.NET Framework | net48 is compatible. net481 was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETFramework 4.8
- Oracle.ManagedDataAccess (>= 23.5.1)
- System.Data.SqlClient (>= 4.8.6)
-
net8.0
- Oracle.ManagedDataAccess (>= 23.5.1)
- Oracle.ManagedDataAccess.Core (>= 23.5.1)
- System.Data.SqlClient (>= 4.8.6)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on ASql:
Package | Downloads |
---|---|
Serilog.Sinks.Database
Serilog sink that writes in one of these five databases (SqlServer, Oracle, MySql, PostgreSQL, Sqlite) |
GitHub repositories
This package is not used by any popular GitHub repositories.