Walk Lightly on this PLANET and yet leave such a FOOTPRINT that cannot be erased for thousands of Years..!!!
Visit Codstech for Cyber Security related Posts !

Visitors

Wednesday, June 29, 2011

VB-26 : Create a database structure for a university



==================================================================================
Before going to do any Database Program ,Click here
 to  understand Database Concepts thoroughly.


That is , Creating Database within VB Platform


==================================================================================

(A) Creating a database :

(Refer 
Linking to Database)  
Creating a database using Access(97) and creating a table.

Steps For crating Database in Access : 
  1. Open Access, select Blank Database, then OK
  2. Give a name (say db1) , then click Create
  3. Select create table in Design View from the dialog window, and OK
  4. Now we will get a window showing three fields a s Field Name,Data Type and Description
  5. In that window, fill the information as 
    Field
    Data bType
    id
    Text
    Name
    Text


    DOB
    Date/Time
    Address
    Text
    Pin
    Number

  6. Right Click on id , then select Primary Kay from the drop down list ..to make the id field a primary key(Because id has to unique and non null value)
  7. Click on Close button
  8. Then a dialog box will appear telling you to give a table name for the created table(Give a name for the table,say, Student Master)
So.now what you get is a database named db1.mdb , with a table named Student Master with no records in it.
Now fill in the recorde in the table and close the window.
==============================================
(B) Providing a front end through VB to link with the DataBase :


Open VB three times.(Activate three instances in VB)
  1. Standard  EXE  (As we normally doing)
  2. ActiveX  DLL
  3. ActiveX  EXE
Note :
  • When the Save button in the form of Standard  EXE is pressed, all the details entered should be verified and then passed on to the ActiveX  DLL program.ActiveX  DLL program is one ,which will implement all the business rules in the project.
  • ActiveX DLL program is going to check all the business rules and then pass the data to ActiveX EXE program
  • ActiveX EXE program is one,which is going to access the database and write the data provided by the ActiveX DLL in the database.This process will be loaded on the server.
----------------------------------------------------------------
1 ) Standard EXE


Create a Standard EXE program,containing a form to accept the student details from the user.


Draw the form as 

Insert 5 Labels, 5 TextBoxes, and one Command Button.



Change the captions of the components a s follows : Label1 to Student ID,

 , Label2 to Name, Label3 to DOB , Label4 to Address, Label5 to Pin . And delete the captions of all the TextBoxes, and change the caption of Command Button to Save as shown above:  


Name the project as ClientEnd and form as StudentEntryForm . This project will be loaded in the client machine.

----------------------------------------------------------------
2 ) ActiveX DLL


Now,again invoke the second instances of VB and choose ActiveX DLL as the project type.
We can see that there is a class module present by default.Click on the name property of the  class module and type studentclass in the place of class1. In the same way,again click on the project window and rename the project to Businessrules.


Tools--> Add Procedure :

  1. Now include some properties into the class studentclass , by clicking the Tools--> add procedure option.
  2. Select type as property , and scope as public.
  3. In the place of name, type studid , then press OK.

Now , we will get a code window as : 

Public Property Get Studid() As Variant
End Property

Public Property Let Studid(ByVal vNewValue As Variant)
End Property
Repeat the above given 3 steps, for all the fields in the table studentmaster . That is , for studid,Name,DOB,Address,and Pin.
And, you will get the following code in the code window.
Code NO : 1


Public Property Get Studid() As Variant
End Property

Public Property Let Studid(ByVal vNewValue As Variant)
End Property

Public Property Get studname() As Variant
End Property

Public Property Let studname (ByVal vNewValue As Variant)
End Property

Public Property Get studdob() As Variant
End Property

Public Property Let studdob (ByVal vNewValue As Variant)
End Property

Public Property Get studadd() As Variant
End Property

Public Property Let studadd (ByVal vNewValue As Variant)
End Property

Public Property Get studpin() As Variant
End Property

Public Property Let studpin (ByVal vNewValue As Variant)
End Property

Now create five private data members(variables) for the class as shown below :
Code NO : 2

Private sid As String
Private sname As String
Private sdob As Date
Private sadd As String
Private spin As Integer
Now,insert the code in the property procedure as shown below :
Code NO : 3

Public Property Get studid() As String
studid = sid
End Property

Public Property Let studid(ByVal vNewValue As String)
sid = vNewValue
End Property
Public Property Get studname() As String
studname = sname
End Property

Public Property Let studname(ByVal vNewValue As String)
sname = vNewValue
End Property
Public Property Get studadd() As String
studadd = sadd
End Property

Public Property Let studadd(ByVal vNewValue As String)
sadd = vNewValue
End Property
Public Property Get studpin() As String
studpin = spin
End Property

Public Property Let studpin(ByVal vNewValue As String)
spin = vNewValue
End Property
Public Property Get studdob() As String
studdob = sdob
End Property

Public Property Let studdob(ByVal vNewValue As String)
sdob = vNewValue
End Property

----------------------------------------------------------------
3 ) ActiveX EXX
Now,again invoke third instance of VB and choose ActiveX EXE as the project type.
You can see that , again there is a default class module with class1 as default class in it. Change the name of the project to backend and class to backendclass .


Create private data members(variables) for backend class by writing the following code in the code window of the class backendclass.
Code NO : 1

Private bsid As String
Private bsname As String
Private bsdob As Date
Private bsadd As String
Private bspin As Integer

Enter the following code to add the procedures in the class backendclass.
Code NO : 2

Private Sub class_initialize()
set db=open database("Give path of db1.mdb")
End Sub

Public Property Get stid() As String
stid = bsid
End Property

Public Property Let stid(ByVal vNewValue As String)
bsid = vNewValue
End Property
Public Property Get stname() As String
stname = bsname
End Property

Public Property Let stname(ByVal vNewValue As String)
bsname = vNewValue
End Property
Public Property Get stadd() As String
stadd = bsadd
End Property

Public Property Let stadd(ByVal vNewValue As String)
bsadd = vNewValue
End Property
Public Property Get stpin() As Integer
stpin = bspin
End Property

Public Property Let stpin(ByVal vNewValue As String)
bspin = vNewValue
End Property
Public Property Get studdob() As Date
stdob = bsdob
End Property

Public Property Let stdob(ByVal vNewValue As Date)
bsdob = vNewValue
End Property

Enter the following commands in the class declaration to establish a connection with the database.
Code NO : 3

Dim db as Database
Dim rs as Recordset
Private Sub class_initialize()
set db=open database("Give path of db1.mdb")
End Sub

================================================
(Not complete......)
Back to Home   &  VB