GetRow - nemiro-net/nemiro.data.dll GitHub Wiki

DataRow is useful when you need to retrieve only single row 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 row = client.GetRow();
  if(row != null)
  {
    // has results
    Console.WriteLine("{0}, {1}, {2}", row[0], row[1], row[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 row As DataRow = client.GetRow()
  If row IsNot Nothing Then
    ' has results
    Console.WriteLine("{0}, {1}, {2}", row(0), row(1), row(2))
  Else
    ' no results
    Console.WriteLine("Data not found...")
  End If
End Using