Sunday, February 6, 2011

Database Exist or not

Create Database
Public Function CreateInstanceDb(ByVal DBName As String) As Boolean
        Dim strSQL As String = "CREATE DATABASE  [" & DBName & "]"
        If ExecuteScript(strSQL) Then
            Return True
        Else
            Return False
        End If
    End Function
Check Database Exist
 Public Function CheckDB(ByVal DBName As String)
        Dim ret_val As String
        conn = Nothing
        conn = New SqlConnection(SQL_CONNECTION_STRING)
        dt = New DataTable
        da = New SqlDataAdapter("SELECT [name] FROM Master..sysdatabases WHERE [name] = N'" & DBName & "'", conn)
        da.Fill(dt)
        If dt.Rows.Count > 0 Then
            ret_val = "S"
        Else
            ret_val = "N"
        End If
        Return ret_val
    End Function

No comments :

Post a Comment