Fast, Easy and Convenient - nemiro-net/nemiro.data.dll GitHub Wiki
Imports namespaces:
C#
using Nemiro.Data;
using Nemiro.Data.Sql;
using System.Data;
Visual Basic .NET
Imports Nemiro.Data
Imports Nemiro.Data.Sql
Imports System.Data
Create instance of the SqlClient class:
C#
using (SqlClient client = new SqlClient())
{
// use instance of SqlClient
}
Visual Basic .NET
Using client As New SqlClient()
' use instance of SqlClient
End Using
or:
C#
SqlClient client = new SqlClient();
Visual Basic .NET
Dim client As New SqlClient()
Everything is ready for use!
For example, get single row:
C#
var row = client.GetRow("SELECT * FROM tableName WHERE id = 1");
if (row != null)
{
Console.WriteLine("{0}", row["id"]);
}
else
{
Console.WriteLine("Data not found...");
}
Visual Basic .NET
Dim row As DataRow = client.GetRow("SELECT * FROM tableName WHERE id = 1")
If row IsNot Nothing Then
Console.WriteLine("{0}", row("id"))
Else
Console.WriteLine("Data not found...")
End If
Get single row using substitution parameters:
C#
client.CommandText = "SELECT * FROM tableName WHERE id = @id";
client.Parameters.Add("@id", SqlDbType.Int).Value = 1;
var row = client.GetRow();
if (row != null)
{
Console.WriteLine("{0}", row["id"]);
}
else
{
Console.WriteLine("Data not found...");
}
Visual Basic .NET
client.CommandText = "SELECT * FROM tableName WHERE id = @id"
client.Parameters.Add("@id", SqlDbType.Int).Value = 1
Dim row As DataRow = client.GetRow()
If row IsNot Nothing Then
Console.WriteLine("{0}", row("id"))
Else
Console.WriteLine("Data not found...")
End If
Yes, you can use an instance of the SqlClient class as a SqlCommand!
It's very simple!
Use the five easy methods to perform the required operations:
- GetData - executes a query and returns instance of DataSet;
- GetTable - executes a query and returns instance of DataTable;
- GetRow - executes a query and returns instance of DataRow;
- ExecuteScalar - executes a query, and returns the first column of the first row in the result set returned by the query;
- ExecuteNonQuery - executes a query and returns the number of rows affected.