Results 1 to 2 of 2

Thread: How to create Ms. SQL database and its table from VB.Net ? ..

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2003
    Posts
    784

    Question How to create Ms. SQL database and its table from VB.Net ? ..

    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

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Ms. SQL? You mean she's single?

    VB Code:
    1. Sub CreateDatabase(ByVal connString As String, ByVal dbName As String, _
    2.     Optional ByVal dropExistent As Boolean = True)
    3.  
    4.     Dim cn As New SqlConnection(connString)
    5.     Try
    6.  
    7.         ' the command for creating the DB
    8.         Dim cmdCreate As New SqlCommand("CREATE DATABASE [" & dbName & "]", cn)
    9.         cn.Open()
    10.         If dropExistent Then
    11. ' drop the existent DB with the same name
    12.             Dim cmdDrop As New SqlCommand _
    13.                 ("IF EXISTS (SELECT name FROM master.dbo.sysdatabases WHERE " _
    14.                 & "name = N'" & dbName & "') DROP DATABASE [" & dbName & "]", _
    15.                 cn)
    16.             cmdDrop.ExecuteNonQuery()
    17.         End If
    18.         ' create the DB
    19.         cmdCreate.ExecuteNonQuery()
    20.     Finally
    21.         cn.Close()
    22.     End Try
    23. End Sub

    Regards,
    The Expert (googler)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width