hai friends,
I dont know how to create database dynamically in vb.net.(if a button is clicked 4 databases in access or sql has to be created).similarly by clicking the delete button the specified database should be deleted.can you help me out with the coding.

Recommended Answers

All 4 Replies

sweetsasthi,

General Syntax:
Create database databasename.

Thank you.
But can I have the exact coding for creating a database when a button is clicked in vb.net

[code = VB.NET]
 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim con As SqlConnection
        Dim sql As String
        Dim cmd As SqlCommand

        con = New SqlConnection("Server=urserver;" & "DataBase=;" & "Integrated Security=ur security;")
        sql = "CREATE DATABASE ABC  ON PRIMARY" + "(Name=abc_data, filename = 'C:\MSSQL7\data\abc.mdf', size=3," + "maxsize=5, filegrowth=10%)log on" + "(name=abc_log, filename='C:\MSSQL7\abc_log.ldf',size=3," + "maxsize=20,filegrowth=1)"
        con.Open()

        cmd = New SqlCommand(sql, con)

        Try
            cmd.ExecuteNonQuery()
            MsgBox("DATABASE Created")
        Catch ex As Exception
            MsgBox("Database Already Exists!")
        End Try

    End Sub

similarly try for Deleting the Database....

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.