==================================================================================
Before going to do any Database Program ,Click here to understand Database Concepts thoroughly.
That is , Creating Database within VB Platform
==================================================================================
This program is connected with the below given 2 programs also...
So , You must refer them while doing the third Program.
They are ;
- How to see Data in Grid
- To create Reports using Data Reports
==================================================================================
(A) Program Design :
- Open a Form. (Form1 ) - Add 10 labels , 10 textboxes , 3 command buttons and one ADO Data Control.
- Then , add a MDI Form .This is to create a Menu in MDI Form.
- Now select Project--> Add Form to add another form (Form2) Add 10 labels , 10 textboxes , 5 command buttons and one ADO Data Control.
Note that , in this project , there is 2 Forms and One MDI Form .
Details of these 2 Forms and one MDI Form is given Below :
=========================================================================
Program Design (1) : Form1
Add 10 Labels , 10 TextBoxes , 3 Command Buttons and One ADO Data Control to Form1 , as given below ;
(Select , Project--> Components-->Microsoft ADO Data Control 6.0 : To get the ADODC into our Form)
(Set the Visible Property of the ADO Data Control to False ) .Note that , by doing so , this will not appear while we run Form1.
That is , like this :
--------------------------------------------------------------------------------------------
Program Design (2) : MDI Form
(Project--> Add MDI_
Then select
Tools--> Menu Editor . Create a
Menu as per shown below:
(Refer
Design a Menu Bar, if you don't know how to create a Menu Bar)
The created Menu Bar in MDI form will look like this :
--------------------------------------------------------------------------------------------
Program Design (3) : Form2
Select , Project --> Add Form to add another form ..
Add 10 Labels , 10 TextBoxes ,5 Command Buttons and One ADO Data Control to Form1 , as given below ;
(Select , Project--> Components-->Microsoft ADO Data Control 6.0 : To get the ADODC into our Form)
(Set the Visible Property of the ADO Data Control to False ) .Note that , by doing so , this will not appear while we run Form2.
--------------------------------------------------------------------------------------------
(B) To Design a Database for this Program :
Now we are going to create a
Database as per the above given details :
We are creating this in MS-Access.
(You can Refer
Linking to Database also to know How to create a Database in Access)
- Open MS Access
- Select Blank Database , give a name and click Create(Here , we are giving a file name - Student)
- Create table in Design view
- Give Details
It will look like this :
Then File --> Save ( Note that , the Table Name is Student)
(C) Now,we are going to connect this Database & VB
(1) Connecting Form-1 :
- Select Form1
- Right Click on ADODC to get its Properties
(Refer Creating Database within VB Platform and note Point Number (4) , "How to connect ADO DataControl with Database" , to know more about ADODC Properties)
- Now , we will get a Property Page , select Use Connection String and Click Build
- And we will lead to Data Link Property pages , and select Microsoft Jet 4.0 OLEDB Provider and Click Next
- Select the created Database Name (Here, we created Student) , and Click Test Connection to know whether the connection is right.Click OK
- Again , back to Property Page , select Record Sourse , and select 2-adCmdTable and select table (Student)
- Apply , OK
======================- Now select The 10 Text Boxs of Form1
- Change all of its DataSource Property to Adodc1
- Now we have to select each TextBoxes separately and change all of its DataField Properties to Name,Course..etc.as given below:
Text | Data Field Property | Data Source property |
Text1 | Name |
Adodc1
|
Text2 | Name of Father |
Text3 | House |
Text4 | Place |
Text5 | District |
Text6 | Admission Number |
Text7 | Course |
Text8 | Date |
Text9 | DOB |
Text10 | Phone |
(2) Connecting Form-2 :
Repeat the above given steps in Form 2 also
(D) Now,we are going to write Code :
(1) Code for MDI Form :
Private Sub mnuadd_Click() Form1.Show End Sub |
Private Sub mnuexit_Click() End End Sub |
Private Sub mnuview_Click() Form2.Show End Sub |
(2) Code for Form1 :
Private Sub Command1_Click() Adodc1.Recordset.AddNew Command1.Enabled = False Command2.Enabled = True End Sub |
Private Sub Command2_Click() Adodc1.Recordset.Update Command1.Enabled = True Command2.Enabled = False End Sub |
Private Sub Command3_Click() Unload Form1 End Sub |
Private Sub Form_Load() Command2.Enabled = False End Sub |
(3) Code for Form2 :
Private Sub Command1_Click() Adodc1.Recordset.MovePrevious If Adodc1.Recordset.BOF = True Then Adodc1.Recordset.MoveFirst Command1.Enabled = False End If Command2.Enabled = True End Sub |
Private Sub Command2_Click() Command1.Enabled = True Adodc1.Recordset.MoveNext If Adodc1.Recordset.EOF = True Then Adodc1.Recordset.MoveLast Command2.Enabled = False End If End Sub |
Private Sub Command3_Click() Adodc1.Recordset.Update End Sub |
Private Sub Command4_Click() Adodc1.Recordset.Delete End Sub |
Private Sub Command5_Click() Unload Form2 End Sub |
Private Sub Form_Load() Command1.Enabled = False End Sub |
(E) Run the Project :
This is the main menu..
Click Student and the sub menus Add and View will appear .
Click Add
Then Add form will appear as ;
Add Details and Click Save...
Do this for any number of students , as you want.
------------------------------------------------------------------------
Again ,Click Student and the sub menus Add and View will appear .
Click View.
Then another Form will appear as ;
We can see and edit the saved details of each students , by selecting the appropriate Commands..
Hope ,you understand the Concept...........
Feel free to write to me your opinions......
(E) Errors :
If found any errors while running your VB program, or want to put your comment about any program , please click Comment section , to post
====================================================================
Back to Home & VB ===========================================================