How to create Database and Table at runtime in SQL-Server.

  • 11 years ago

    Dear Sir,


    Please somebody tell me how to create Database and table at runtime by use with SQL -Server


    Thank you,


  • 11 years ago

    You should be able to make an ADO.Net connection to the database and issue the DDL commands that you need to create your database and table. For example:

            Dim conn As New SqlConnection("Persist Security Info=True;User ID=tim;Initial Catalog=master;Data Source=YourSQLServer")
            Dim cmdDB As New SqlCommand("CREATE DATABASE [NewDatabaseName]", conn)

    Next, connect to your new database and issue the CREATE TABLE command.


  • 11 years ago

    Dear TimL

    Firstly I like to very thanks full to your code. But I have problem as I’m new to so that I’m unable to understand some code lines without full code. If you can send me full code, which I’m very thanks full to you.

    Thank you,



  • 11 years ago

    Unfortunately, I don't have time to write a full solution but if you're new to this, I suggest you read up a bit on ADO.Net. James has a good article here:

    The important point for you is to use the 'CREATE DATABASE' and 'CREATE TABLE' SQL to do what you need to do.


Post a reply

Enter your message below

Sign in or Join us (it's free).


Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“My definition of an expert in any field is a person who knows enough about what's really going on to be scared.” - P. J. Plauger