How do I use VB .Net to delete a table in SQL Server?
Posted on 2006-03-23
The code attached below is crashing at the point marked <=***
Where in the previous code have I gone wrong?
Many thanks in advance,
Public Function DropDatabase(ByVal connString As String, ByVal sDBName As String) As Boolean
Dim cn As New SqlConnection(connString)
'Dim cmdDrop As New SqlCommand("DROP DATABASE " & sDBName, cn) [my note: I've alternated between this line and the next by remarking the other one out]
Dim cmdDrop As New SqlCommand("DROP DATABASE " & sDBName)
WriteToFile("Setup", "Database Deleted")
Catch ex As Exception
MsgBox("Encountered an Error in deleting the database: " & sDBName & vbCrLf & "It is important that you contact the SQL Server Administrator and tell him/her that this database needs to be deleted!", MsgBoxStyle.Critical)
WriteToFile("Setup", "Database not deleted (" & sDBName & ")" & vbCrLf & "Connection String= " & connString)