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

Tuesday, June 28, 2011

VB-25 : Linking to Database

How to create database & tables ??  SQL-create Database & Table

==================================================================================
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 :


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 Type
    Width
    Roll Number
    Text
    5
    Name
    Text
    50
    Age
    Numeric
    2
    Sex
    Text
    1
  6. Right Click on Roll Number , then select Primary Kay from the drop down list ..to make the Roll Number field a primary key(Because roll number 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
  1. Insert 4 Labels, 4 TextBoxes, and one DataControl . 
  2. Change the captions of the components a s follows : Label1 to RollNo , Label2 to Name, Label3 to Age , Label4 to Sex. And delete the captions of all the TextBoxes, and change the caption of data control to Student Master File as shown above :      
  3. From the databasename property ,choose the path where you saved the database file  (here,db1.mdb)  , by pressing the ellipse button (....) .
  4. Now, we have to select the tablewhich you will be linking your form to. To do this , click on the RecordSource property of the Data Control , and you will get all the tables listed,  which are a part of the data base to which this data control is linked with.(Since only one table was created in the database, only one table is shown in the list).
  5. Select all the textboxes and change the DataSource property to Data1, since all the text boxes have to be linked with the database that is linked with data control Data1
  6. Select the text1 text box and change the DataField property.When you click on the data field property, it will show you a drop down list.All you have to do is to , choose the field with which you want this text box to be linked with.So choose RollNo from the list.
  7. Like above, change the data field property of Text2 to Name, Text3 to Age and text4 to Sex.
  8. Now , every control in the form1 is linked with some or the other component to import the data from the data base db1.mdb which we created in MS-Access.
  9. Save the project
  10. Now, click on the start button to run the application, use navigation buttons to navigate the records in the database.
=========================================================================
Back to Home   &  VB