DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   VB.NET (http://www.daniweb.com/forums/forum58.html)
-   -   how to create database (http://www.daniweb.com/forums/thread201657.html)

sweetsasthi Jul 4th, 2009 10:59 am
how to create database
 
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.

adatapost Jul 5th, 2009 12:48 am
Re: how to create database
 
sweetsasthi,

General Syntax:
Create database databasename.

sweetsasthi Jul 6th, 2009 4:03 am
Re: how to create database
 
Thank you.
But can I have the exact coding for creating a database when a button is clicked in vb.net

Piya27 Jul 6th, 2009 6:52 am
Re: how to create database
 
[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

Piya27 Jul 6th, 2009 6:53 am
Re: how to create database
 
similarly try for Deleting the Database....


All times are GMT -4. The time now is 8:44 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC