Hello friends, hope you all are enjoying good health. Today, I am going to share How to create a Database in Microsoft Visual Studio 2010. Around two to three months ago, I have shared a topic on Microsoft Visual Basic 2010 - Com Port in which I have explained completely how to make the serial communication in Microsoft Visual studio using visual basic language. Today I am going to share another complete tutorial on how to create a database in Microsoft visual studio. Its a most common project in computer science which usually students do as a semester project, so I thought of sharing it here.
I have divided this project or tutorial into three parts, today we will just create a simple database in which we can add out objects easily and later on we will add few functionality in it. In this tutorial we are going to create a database driven application. In this tutorial we are going to create a simple contact form database. Simply follow these steps. I have also posted How to add Button Control in VB Database and How to Update Database Table with Programming in VB 2010. You must read them as well if you are planning to work on VB database. So, let's get started with creating a Database in Microsoft Visual Studio 2010.
Creating a Database in Microsoft Visual Studio 2010
I have tried my best to make this creation of database in Microsoft Visual Studio as simple as possible, that's why I have added screenshot of each step with commenting but still if you guys have any problem at any step ask in comments. At the end of this tutorial, we will create a database driven application as shown in the figure below:
Step 1 : Creating New Project
First of all open the Microsoft Visual Studio 2010 and click on the New Project as shown in figure below:
After clicking it, the below screen will show. Now, choose the language and the project type and then give this project a name and click OK. In our project I am using Visual Basic language and project type is Windows Form Application.
It will create a new project for you, where we are gonna add the database.
Step 2 : Creating a Database
Now we are gonna create a database in our project.
For this first go to the Solution Explorer in your project.
Now right click on your project name and then click on Add and finally click on New Item.
Note :
If you can't find it click on View in the above menu tab and then click on Solution Explorer.
If you can't find the Solution Explorer then click on View in the above menu tab and then click on Solution Explorer.
After clicking on New Item, a list of items will open up as shown in below figure. Now from these select the Service Based Database. Give it a name like I gave it Contacts.mdf and then click on Add.
That's now gonna open up a data source wizard as shown in below figure. Just cancel it for now as we don't have anything right now to add in our database.
Now our database has been created which you can also see in the solution explorer but rite now its empty, so now in the next step we are gonna add a table in our database.
Step 3 : Creating a Table
Now, double click on the database which we just created in the step 2 and named it Contacts.mdf. (You will find it in Solution Explorer)
Double clicking the database will open up Server Explorer.
Now in the Server Explorer, right click on the Tables and then Add New Table.
Now, it will open a Table where we will add the Columns Name of our Table.
I have given the first Column as ColumnID and Data Type is int and unmark the Allow Nulls Option.
Now click on the Primary Key as shown in below figure.
After that go in the properties of table and click on Identity Specification to expand it.
Now change the option from No to Yes.
I have done this to make it auto incremented, now as you add the data in it the ContactID will be incremented on its own showning you the total number of data present in the Table.
Now quickly fill the other columns name as shown in below figure, you can choose any data type you want but I have choosen varchar(50).
Now click on Save button to save the table and it will ask for the table name.
Give the table name and click Ok.
Now close this tab.
Now our table has been created, in the next step we are gonna add some data in the table.
Step 4 : Adding Data in the Table
In order to add data in the table we just created, go to Server Explorer and Expand the Table Section.
In the Table Section, you will get your table which we created in the Step3.
Right Click on the Table which we named Contact Form and then Click on Show Table Data.
It will open up the Contact Form data table. Now fill the few lines as you can see I have added few info in it and then click Save.
It will ask for the name, remain the name as it is and click Save.
Uptill now, we have created our database and then we created a table and added some data in it.
Now we are gonna attach a data source with our database in the next step.
Step 5 : Attach a Data Source
Now we need to attach a data source with our database.
For this first click on Data and then Add New Data Source as shown in below figure.
Now it will open the data source configuration wizard. Select the database and click on Next.
Again click on the Next as shown in below figure.
Now we need to attach this data source with the database which we created in the Step 2, so select the Contacts.mdf database and click Next.
Now it will ask for the components you want to add in your data source.
Click on the Tables to expand and the select Contact Form, this is the table which we created in step 3.
Now click Finish.
Now we have created our data source which contains the table. In the next step we are gonna add this database on our form so that we can use it easily.
Step 6 : Adding Database on the Form
Now go to the Data Source, if you cant find it then open it from Data tab in the top menu.
Now click on the Contact Form (which is our table) and drag it to the Form Board as shown in the below figure.
Now re size it using the mouse according to your form.
Next click on the Contact Form in the Data Source and select Details, it will give us detail view of our database.
Now again click the Contact Form and drag it in the Form Board and it will show like detail view as you can see in the figure below.
We have add the both views on our board. Now run it and your project will open up.
Now you can add or delete or edit any column and then save it.
So the final form of our project is something like that.
You can see the above bar where are options to add, delete or move forward, backward etc.
In the next tutorial we will add some functionality in it like adding new column with button and save etc.
Hope you guys enjoyed it. If someone needs this database in Microsoft Visual studio along with the exe file of this project then Subscribe Us via Email and post your email in the comments and we will email it to you.
That's all for today, and I hope you guys are not familiar with How to create Database in microsoft visual studio 2010, will meet you in the next tutorial, till then take care ALLAH HAFIZ. :))
syedzainnasir
I am Syed Zain Nasir, the founder of The Engineering Projects (TEP). I am a
programmer since 2009 before that I just search things, make small projects and now I am sharing my
knowledge through this platform. I also work as a freelancer and did many projects related to
programming and electrical circuitry. My Google Profile+Follow
Get Connected
Comments on ‘’ Create Database in Microsoft Visual Studio ‘’ ( 31 )
0
Says:
Could you send me the application?
Frank@wirepower.com.au
Reply
100
1
amit
Says:
sir its easy to design tables can you make a tutorial how data will be saved ,delete , update,find ...i get sucess to make all you explain but data in tables are not storing properly .please provide a solution for this one.
thank you
Reply
100
2
vesodimov
Says:
Visual Studio 2013
I can't make Step 5 - I don't have a DATA in soft. How Attach a Data Source in VS2013 ?
Regards
Reply
100
3
emmysmith
Says:
thank you sir , for your quick reply, keep the fire burning . i will go through the guides and get back to u sir,
happy weekend .
Reply
100
4
emmysmith
Says:
That is best and helpful tutor! Am new to VB , Also want to learn how to create database using VB, Pls can u send Send me all tutorials you have on Visual basic especially on database. thanks sir. emmy
NB I WILL LIKE TO SUBSCRIBE FOR YOUR NEWS LETTER Thank u
Reply
100
5
syedzainnasir1
Says:
Hi,
Thanks for the appreciation. it works as a fuel for our team. :))
All the links for dealing with database in vb are given in this article. I think I have posted 3 or 4 article and these will be enough for you to learn the basics of database handling.
Thanks.
Reply
100
6
anuraglala
Says:
Very nice sir
hats off
Reply
100
7
tmmanik
Says:
Pls give me your VB project code.
tm.manik.3e@gmail.com
Reply
100
8
Says:
Can We attach excel file with this like Students Details file in it .
Reply
100
9
Says:
Hi, your tutorial is indeed great. I wish to have your tutorials on Visual basic, particularly database. Thanks. .
Reply
100
10
shah
Says:
How to connect rfid data with database visual studio ultimate? What i must to do?
Reply
100
11
syedzainnasir1
Says:
Hi, Kindly add me to Skype and I will help you out. Its not that easy. Thanks.
Reply
100
12
montypatel
Says:
Its a great tutor, best tutor i hv ever read, keep it up
Reply
100
13
daniel1
Says:
Please Send me all tutorials you have on Visual basic especially on database. thanks
Reply
100
14
zaid
Says:
hi
I want to create a database using RFID parking system, database using Visual Basic, can help me to create a database entry and exit to the parking system?
Reply
100
15
andreolushola
Says:
I love this tutorial, is very straight forward
Reply
100
16
budnew
Says:
New to VB. Want to learn how to use database from VB.
Reply
100
17
morad
Says:
Hello
thanks for your explaning
i have problem .... i want to add another form for searching ? how can make full search ?
Reply
100
18
syedzainnasir1
Says:
Contact me on skype n I'll explain but adding a search form is quite simple, search a little online n you will find the solution
Reply
100
19
mohammed1
Says:
That is best and helpful tutor! so please send me the application with its .exe and full tutor.
thanks a lot
Reply
100
20
shuaibp
Says:
tanks.can i update this table with ma phn msg
Reply
100
21
syedzainnasir1
Says:
Yeah you can do that as well, not that difficult.
Reply
100
22
Says:
Hello my friend thanks for this tutorial My name is PAUL I'm from Greece I have one problem when i use the programm and i wrote in my language shows the character with question marks .did you know what to do with this?
Reply
100
23
Says:
hmmm that's just because of the non supportive behavior of software for this language .... I think you should go with English.
Reply
100
24
Says:
Thanks for your reply when i use english words is ok i check for unicodes and i change the fields to greek_BIN in the data table but the problem is there, change the greek letters with ??????
Reply
100
25
Says:
Hi,
Test it using words of English .... I think the problem is because the software is not supporting your language .... Test it with english or numeric words .... if its work fine then check for the the language update ....
Let me know if you cant resolve this issue.
Thanks.
Reply
100
26
Says:
Philip Thanks bro, I have posted the second part of this tutorial. enjoy !!!
@ William Thanks for appreciation bro.
@ Qasim I have emailed to to you. Thanks for subscribing and stay connected.... :))
Reply
100
27
prerna
Says:
It is really nice explanation. Further this, I want to add database for any application layer. How can i do that?
Reply
100
28
Says:
qasim.iqbal@gmail.com .... That's my id and I have joined the newsletter as well kindly send me this complete project.
Thanks in advance
Reply
100
29
Says:
hats off +1
Reply
100
30
Says:
awesome post man waiting for the next one kindly post it asap as i am working on a similar project in the lab Thanks again
Reply
My name is PAUL I'm from Greece
I have one problem when i use the programm and i wrote in my language
shows the character with question marks .did you know what to do with this? Reply
i check for unicodes and i change the fields to greek_BIN in the data table but the problem is there, change the greek letters with ?????? Reply
Test it using words of English .... I think the problem is because the software is not supporting your language .... Test it with english or numeric words .... if its work fine then check for the the language update ....
Let me know if you cant resolve this issue.
Thanks. Reply
@ William Thanks for appreciation bro.
@ Qasim I have emailed to to you. Thanks for subscribing and stay connected.... :)) Reply
Thanks in advance Reply
waiting for the next one
kindly post it asap as i am working on a similar project in the lab
Thanks again Reply