A Wrapper Class for the SQL Server Based Data Access Helper - A Wrapper method to test whether a row exists
(Page 5 of 7 )
The following wrapper method is mainly used to test whether a row exists or not:
PublicFunction isRowExists(ByVal sqlSELECT As String) As Boolean
Try
Dim dr As DataRow
dr = getDataRow(sqlSELECT)
If dr Is Nothing Then
Return False
Else
Return True
End If
Catch ex As Exception
Return False
End Try
End Function
You can modify/overload the above to make it more flexible as follows:
PublicFunction isRowExists(ByVal TableName As String, ByVal ColumnName As String, ByVal ValueToSearch As String, Optional ByVal PatternSearch As Boolean = False) As Boolean
Try
Dim sql As String
If PatternSearch Then
sql = "SELECT * FROM " & TableName & " WHERE " & ColumnName & " like '%" & ValueToSearch & "%'"
Else
sql = "SELECT * FROM " & TableName & " WHERE " & ColumnName & " = '" & ValueToSearch & "'"
End If
Dim dr As DataRow
dr = getDataRow(sql)
If dr Is Nothing Then
Return False
Else
Return True
End If
Catch ex As Exception
Return False
End Try
End Function
Next: Adding a wrapper to execute SQL statements >>
More MS SQL Server Articles
More By Jagadish Chaterjee