Introduction: Create an SQL Database Using Visual Studio
How to Create an SQL Database
Using Windows Virtual Basic
The way we access and treat information has developed and evolved and as such databases have become more important. Databases are a complex and intricate way to store and alter data. As with most technological advances databases can be hard to handle, so these instructions will be a step-by-step walkthrough on simple database. This set of instructions will particularly useful to users with a reasonable amount of CS experience who have dealt with similar programs.
· Windows 8 running machine
· Windows Virtual Studio 2012 or 2013
· Oracle’s SQL Developer (Optional)
· Open Mind J
The main language I will use for my tutorial is SQL and it will be run on an application called Oracle SQLDeveloper. Once downloaded a quick setup will be required, after which the database processes. The installation process will require a working system with enough memory to store the applications to be installed as well as a running Internet connection. If you have no previous experience with Visual Studio or C# I recommend that you make use of some short video tutorials on YouTube to get you started.
Step 1: Step 1 (getting Started)
Starting up the Visual Basic App is the first thing we will do. While this step should be quite straightforward a is imperative that it is not rushed over; as getting used to the Virtual Studio setting will make this tutorial a lot easier. The start page will look something like this
Step 2: Step 2 (VS Project Creation)
Things will start to get interesting now; we are going to make a new project in Visual Basic. Click on the File tab, under New select New Project where a window will appear. Under Templates choose the Visual C# section and to the right of that select Window Form Application, change the file name to something recognizable like DataBaseTut (Database Tutorial). If these steps have been followed you would have successfully created a project.
Step 3: STEP 3 (ADDING a LOCAL DATABASE)
If as expected you have created the project your should now see the main page, complete with an empty smaller titled Form1 and the properties section on the right. Now we right-click the DataBaseTut tab on the right and select add new item, this window should appear:
Step 4: STEP 4 (SETTING UP THE NEW DATABASE)
As you can imagine our newly created database would have no content, which makes for dull viewing. This next step involves creating tables for the database. We will use pretty generic values now but this is something that can be altered once you get a hang of it.
Now right click the Table tab and select add New Table option, the dbo.Table [Design] window will appear; this is where we will add tables. I will create two columns, specify what can be entered into them as well as rename the Table as StudentTab. After that the screen should look like this:
While you may have been successful in updating the database but it won’t show up on the main page, you will have to go to the Server Explorer then click on the database and the select Tables then hit refresh; this should fix the issue.
Step 5: STEP 5 (EDITING THE FORM)
We will now work with the Form window on the main page now; this will serve as the main display for the database. Click the toolbox on the left of the screen and add a label to the form and alter the size to make the text readable, do this twice. These labels should be stacked on top of each other with the text in them being “StudentID” and “StudentName” respectively. Add textboxes from the ToolBox to the right of the respective labels as shown below:
Step 6: STEP 6 (MORE FORM EDITING)
We are starting to make some real progress with the database and the form will be the access point for data entries in the database. We are going to add from the Data section of the Toolbox a DataGridView. Shift this newly opened window to the right, as I will do for organization sake. We will need to connect this grid view to a data source. The upper right corner of the grid view will pull up the window for this. The database we have made will be available to set up for this window.
After connecting the database the grid will display the info from our database:
Step 7: STEP 7 (EDITING THE GRID)
Now the framework for the buttons and functions will now be added; this will involve some coding that will be laid out pretty simply. The code should be as follows:
Step 8: STEP 8 (MORE CODE)
this program it is imperative that the code entered correctly; hence it taking two steps. Any slight variation will cause problems so the importance of code accuracy cannot be understated. Below is the complete code from the Form1.cs:
Step 9: STEP 9 (TRYING TO RUN YOUR CODE)
Now we get to test the code we have written. Here we should be able to add data to the database from the Form1 page:
If after clicking the Debug but the above picture doesn’t pop up it is likely that there is erroneous code somewhere check back in the Form1.cs page to make sure you have all the correct info.
Step 10: STEP 10 (ALTERING THE DATABASE)
We are almost done; now that we have the Form1 page done we can start to feed our database with (you guessed it) data! The data you input is solely up to you but here is a snapshot of the screen right after a successful entry:
With this you have successfully created a basic but usable database using Microsoft Visual Studio!
We have a be nice policy.
Please be positive and constructive.