Language: Add Datatable.First Extension method

This commit is contained in:
Jonathan Jenne
2021-12-16 13:53:21 +01:00
parent 24f4051b1c
commit 9deeec86e4
2 changed files with 14 additions and 2 deletions

View File

@@ -0,0 +1,24 @@
Imports System.Runtime.CompilerServices
Public Module DataTableEx
<Extension()>
Public Function ItemEx(Of T)(pRow As DataRow, pFieldName As String, Optional pDefaultValue As T = Nothing) As T
Try
Return Utils.NotNull(pRow.Item(pFieldName), pDefaultValue)
Catch ex As Exception
Return Nothing
End Try
End Function
<Extension()>
Public Function First(pTable As DataTable) As DataRow
Try
If pTable Is Nothing OrElse pTable.Rows.Count = 0 Then
Return Nothing
End If
Return pTable.Rows.Item(0)
Catch ex As Exception
Return Nothing
End Try
End Function
End Module