Linking Database To A VB Project (Lesson 5)
Linking Database To A VB Project (Lesson 5)
Net
Using Microsoft Access Database Product
Terminologies
• Database – a special repository—consists of one or more physical
files—used to store and retrieve data.
• Relational database – a specific type of database where data rows
are stored in separate tables, and the tables are related to each other
by key values.
• Table – basic database object that stores data
• Row = a row is a record representing an individual, course or student.
• Column = a column is a field that stores data.
• Key Column (Field) – uniquely identifies a row in a table
• Relationship- an association between two tables.
Database Products
• Oracle (by Oracle Corporation) and DB2 (by IBM) for large systems—
these are competing relational database management systems.
• Microsoft SQL Server for mid-sized systems and larger scalable
systems.
• Microsoft Access and other small-sized, individual user or small group
systems.
Table Types
• Base table – a base table is one that stores basic information about
entities.
• Association table – an association table stores information about
associations between entities.
• Validation table – a validation table validates data entered into
another table. (use of validation rules)
Process of connecting a database to Visual
Studio
STEP ONE:
Open Access Database and create a new database. Save the database
using (2002-2003) format (.mdb).
STEP TWO:
Create tables and insert a few records. Save and close the database.
STEP THREE:
Open Visual Studio and create a new project.
Add forms based on the tables from database.
Process of connecting a database to Visual
Studio contd,
STEP FOUR:
Add Data sources from the “Data” tab to link to the database.
STEP FIVE:
Drag the tables to their respective forms.
STEP SIX:
Run the system to test for records navigation.
Process of connecting a database to Visual
Studio contd,
STEP SEVEN:
Add Navigation Buttons.
Previous, Save Data, Delete, Add New, Next
STEP EIGHT:
Code the buttons.
Save Data Button
Try
EmployeeTableBindingSource.EndEdit()
TableAdapterManager.UpdateAll(EmployeeDataDataSet)
MsgBox("Success")
Catch ex As Exception
MsgBox("Error! Please recheck fields and try again")
End Try
Delete Button
EmployeeTableBindingSource.RemoveCurrent()
TableAdapterManager.UpdateAll(EmployeeDataDataSet)
MsgBox("Current record deleted successfully")
Coding the buttons
Next Button
Table1BindingSource1.MoveNext()
Previous Button
Table1BindingSource1.MovePrevious()
Add New Button
Table1BindingSource1.AddNew()