Dear The Expert,
How to create Ms. SQL database and its table from VB.Net ? .. where can I find complete article or sample for this? .. thanks
Winanjaya
Dear The Expert,
How to create Ms. SQL database and its table from VB.Net ? .. where can I find complete article or sample for this? .. thanks
Winanjaya
Ms. SQL? You mean she's single? :afrog:
VB Code:
Sub CreateDatabase(ByVal connString As String, ByVal dbName As String, _ Optional ByVal dropExistent 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 dropExistent Then ' drop the existent 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
Regards,
The Expert (googler)