ExtensionMethod.NET Home of 880 C#, Visual Basic, F# and Javascript extension methods

HasRecords

The idea is to have a method which spells out a question, are there any records which for some might be reading code easier

Source

<System.Runtime.CompilerServices.Extension()> _
Public Function HasRecords(ByVal dt As DataTable) As Boolean
    Return dt.Rows.Count > 0
End Function

Example

Dim table As DataTable = New DataTable()
With table.Columns
    .AddRange(New DataColumn() _
       { _
          New DataColumn("ID", System.Type.GetType("System.String")), _
          New DataColumn("FirstName", System.Type.GetType("System.String")), _
          New DataColumn("LastName", System.Type.GetType("System.String")) _
       } _
    )
End With

table.Rows.Add(New Object() {"100", "Mary", "Smith"})

If table.HasRecords Then
    Console.WriteLine("     Yes")
Else
    Console.WriteLine("No")
End If

table.Rows.RemoveAt(0)

If table.HasRecords Then
    Console.WriteLine("Yes")
Else
    Console.WriteLine("No")
End If

Author: Kevin S Gallagher

Submitted on: 3 nov. 2009

Language: VB

Type: System.Data.DataTable

Views: 4711