How to Create a Database in VB.Net

Updated July 19, 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)

Cite this Article A tool to create a citation to reference this article Cite this Article

About the Author

Jim Campbell has been a computer engineer for over five years. He excels in hardware repair, computer programming and troubleshooting, and software design. He is currently attending Florida Atlantic University, pursuing a master's degree in computer and electrical engineering and fine-tuning his technical writing abilities.