Tuesday, July 21, 2009

Check if a table exist using EntitySpaces in DotNetNuke

Using esUtility ExecuteScalar method the function(VB.Net) below given the table name will return true if the table exist in the database otherwise it will return false.

Public Shared Function TableExist(ByVal tableName As String) As Boolean
Dim strSQL As String = "SELECT Count(*) FROM dbo.sysobjects WHERE id = object_id(N'{databaseOwner}[{objectQualifier}" & tableName & "]') AND OBJECTPROPERTY(id, N'IsTable') = 1"
strSQL = strSQL.Replace("{databaseOwner}", DotNetNuke.Common.Utilities.Config.GetDataBaseOwner())
strSQL = strSQL.Replace("{objectQualifier}", DotNetNuke.Common.Utilities.Config.GetObjectQualifer())

Dim util As New esUtility()
If util.ExecuteScalar(esQueryType.Text, strsql) > 0 Then
Return True
Else
Return False
End If
End Function





No comments:

Post a Comment