GetTable - nemiro-net/nemiro.data.dll GitHub Wiki
DataTable is useful when you need to retrieve multiple rows of data.
C#
using (SqlClient client = new SqlClient())
{
// sql query or stored procedure name
client.CommandText = "MyStoredProcedure";
// parameters (if necessary)
client.Parameters.Add("@par1", SqlDbType.Int).Value = 123;
client.Parameters.Add("@par2", SqlDbType.NVarChar, 50).Value = "hello, world!";
// query execution
var table = client.GetTable();
if(table.Rows.Count > 0)
{
// has results
Console.WriteLine("Rows count: {0}", table.Rows.Count);
// each the table row
foreach(DataRow r in table.Rows)
{
Console.WriteLine("{0}, {1}, {2}", r[0], r[1], r[2]);
}
}
else
{
// no results
Console.WriteLine("Data not found...");
}
}
Visual Basic .NET
Using client As New SqlClient()
' sql query or stored procedure name
client.CommandText = "MyStoredProcedure"
' parameters (if necessary)
client.Parameters.Add("@par1", SqlDbType.Int).Value = 123
client.Parameters.Add("@par2", SqlDbType.NVarChar, 50).Value = "hello, world!"
' query execution
Dim table As DataTable = client.GetTable()
If table.Rows.Count > 0 Then
' has results
Console.WriteLine("Rows count: {0}", table.Rows.Count)
' each the table row
For Each r As DataRow In table.Rows
Console.WriteLine("{0}, {1}, {2}", r(0), r(1), r(2))
Next
Else
' no results
Console.WriteLine("Data not found...")
End If
End Using