Database programming in VB for begginers

The built-in add-in tool ,Visual Data Manager, available in Visual Basic is used for creating database. Visual Data Manager can be used to create tables, add new data as well as edit data. Besides that, it can be used to modify table structure.

To create the database follow the steps

Step-1
 To activate or start  Visual Data Manager, select Add-In menu of VB project window from there select the first item, Visual Data Manager.On clicking the Visual Data Manager a window titled VisData will pop up. From the menu of  this window, click File and choose New to create a new database.(Steps:-New->Microsoft-Access->Version7.0MDB)
See the figures below:








Now, Name DataBase and Save it.




Step-2
After creating the database, VisData opens two window the Database Window and the SQL Statement window. On Database Window right click the mouse to create a new table or right-click on properties in Database Window to bring up the Table Structure window(see figures below). On right clicking a pop-up will show select new table option to open a window for entering table structure.










Now you can enter the name for you table  in the  table structure window(Table Name text box).




Step-3
Click Add Field button on Table Structure window to build the table and create the fields with proper data-types for example if you are creating student table the field will be Name roll_num,marks etc and these field should have data-types like  string/text,number,float etc. 

On clicking Add Field button the below shown window will appear
Add field name , type (numerical, currency etc), size




After completing the above press Build the Table button, on Table Structure window,to create the table

Here I created a sample DataBase which only have two field  for Name and Salary(field name are pName and pSalary) of types string and currency respectively.


The newly created table will appear in the Database Window



Step-4
After the above 3 steps we have a table listed in Database Window double click on it. A window will be displayed(Dynaset Window). Use Add and Update button to adding and updating recordes one by one. After you done close the Dynaset window by clicking Close
the steps are given in below figures:
Click Add button a window will appear

The newly opened window enter the data and click the Update button





Follow this two steps until you have enough data for your DataBase. When you finished click Close button to exit.

Step-5
Now Build an application to show the datas stored in DB. Here I build the Application with two text box and two labels (Name and Salary)are named Name and Salary and add a DataControl
Steps:
Drag red arrow marked Control into your application .(I already did which is labeled Data1 with scrolls). Give Control a caption I, gave Data1.

Now, select your DataBase which you created


Select The Recordset(which is Table name)

Now Select the text box on your application one by one and provide the DataSource(Here it is Data1) and DataField(the field should be equal that is Name text box should point to name field in your database field and salary text box to salary field in your database)

After completing the above  run your application. Click arrow mark on DataControl to scroll through your stored data






No comments: