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

  • 10 years ago

    Dear Sir,

     

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

     

    Thank you,

    Nishantha.

  • 10 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)
            DBConnection.Open()
     cmdDB.ExecuteNonQuery


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

     

  • 10 years ago

    Dear TimL

    Firstly I like to very thanks full to your code. But I have problem as I’m new to vb.net 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,

    Nishantha

     

  • 10 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: http://www.developerfusion.co.uk/show/4278/1/

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

    Tim

Post a reply

Enter your message below

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

Contribute

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.

“Measuring programming progress by lines of code is like measuring aircraft building progress by weight.” - Bill Gates