Ultimi Articoli
Visual Basic
Connessione a Database Microsoft SQL
Visual Basic
I controlli ListBox e ComboBox
ASP
Verificare l'esistenza di un file sul Server
Visual Basic
Informazioni aggiuntive sugli ActiveX
Visual Basic
Installare un file .inf

Visual Basic .NET

SORGENTI - DATABASE - CREARE UN DATABASE SQL SERVER A RUNTIME



Sub CreateDatabase(ByVal connString As String, ByVal dbName As String, Optional ByVal dropExisting As Boolean = True)
Dim cn As New SqlConnection(connString)
Try
' the command for creating the DB
Dim cmdCreate As New SqlCommand("CREATE DATABASE [" & dbName & "]", cn)
cn.Open()
If dropExisting Then
' drop the existing DB with the same name
Dim cmdDrop As New SqlCommand("IF EXISTS (SELECT name FROM master.dbo.sysdatabases WHERE name = N'" & dbName & "') DROP DATABASE [" & dbName & "]", cn)
cmdDrop.ExecuteNonQuery()
End If
' create the DB
cmdCreate.ExecuteNonQuery()
Finally
cn.Close()
End Try
End Sub