How to Create a Database in VB.Net

Written by jim campbell | 13/05/2017

The VB.NET programming language contains functions and libraries that let you manipulate databases. You can query the database, but you can also create a new database on the server. This code is beneficial for programmers who create database applications for internal employees or database administrator clients.

Click the Windows "Start" button and select "All Programs." Click "Microsoft .NET Framework" and then click "Visual Studio."

Right-click the VB.NET file you want to use to create the database. Click "View Code." At the top of the opened file, copy and paste the following library files needed to create the database:

Import System.Net.SQLClient

Import System.Net.Data

Create the connection string. The connection string contains all drivers and properties needed to connect to the server. Use the following code to connect to a local SQL Server:

conn.ConnectionString = "Integrated Security=SSPI;Initial Catalog=mydb;Data Source=localhost;"

Create the "create database" query. The following code shows you how to create a database named "customers":

query = "create database customers on primary"

Execute the query to create the database. The following code creates the database:

cmd = New SqlCommand(query, con)

By using the site, you consent to the use of cookies. For more information, please see our Cookie policy.