Academic Tutorials



English | French | Portugese | German | Italian
Google

Home Testimonials Advertise Contact Us About Us Link to Us
Source Codes E-Books Downloads Jobs Web Hosting Chats

Visual Basic Tutorial
Introduction to VB
Building a Visual Basic Application
Writing the Codes in VB
Working With Controls
Managing Visual Basic Data
Working With Variables
Controlling Program Flow
More on Program Control
Looping in VB
Introduction to VB Function
Creating VB Function For MS Excel
Arrays in VB
Working With Files
Creating Multimedia Applications in VB
Creating database applications in VB
Creating VB database applications using ADO control

HTML Tutorials
HTML Tutorial
XHTML Tutorial
CSS Tutorial
TCP/IP Tutorial
CSS 1.0
CSS 2.0
XML Tutorials
XML Tutorial
XSL Tutorial
XSLT Tutorial
DTD Tutorial
Schema Tutorial
XForms Tutorial
XSL-FO Tutorial
XML DOM Tutorial
XLink Tutorial
XQuery Tutorial
XPath Tutorial
XPointer Tutorial
RDF Tutorial
SOAP Tutorial
WSDL Tutorial
RSS Tutorial
WAP Tutorial
Web Services Tutorial
Browser Scripting
JavaScript Tutorial
VBScript Tutorial
DHTML Tutorial
HTML DOM Tutorial
WMLScript Tutorial
E4X Tutorial
Server Scripting
ASP Tutorial
PERL Tutorial
SQL Tutorial
ADO Tutorial
CVS
Python
Apple Script
PL/SQL Tutorial
SQL Server
.NET (dotnet)
Microsoft.Net
ASP.Net
.Net Mobile
C# : C Sharp
ADO.NET
VB.NET
VC++
Multimedia
SVG Tutorial
Flash Tutorial
Media Tutorial
SMIL Tutorial
Photoshop Tutorial
Gimp Tutorial
Matlab
Gnuplot Programming
GIF Animation Tutorial
Scientific Visualization Tutorial
Graphics
Web Building
Web Browsers
Web Hosting
W3C Tutorial
Web Building
Web Quality
Web Semantic
Web Careers
Weblogic Tutorial
SEO
Web Site Hosting
Domain Name
Java Tutorials
Java Tutorial
JSP Tutorial
Servlets Tutorial
Struts Tutorial
EJB Tutorial
JMS Tutorial
JMX Tutorial
Eclipse
J2ME
JBOSS
Programming Langauges
C Tutorial
C++ Tutorial
Visual Basic Tutorial
Data Structures Using C
Cobol
Assembly Language
Mainframe
Forth Programming
Lisp Programming
Pascal
Delphi
Fortran
Oops
Data Ware Housing
CGI Programming
Emacs Tutorial
Gnome
ILU
Soft Skills
Communication Skills
Time Management
Project Management
Team Work
Leadership Skills
Corporate Communication
Negotiation Skills
Database Tutorials
Oracle
MySQL
Operating System
BSD
Symbian
Unix
Internet
IP-Masquerading
IPC
MIDI
Software Testing
Testing
Firewalls
SAP Module
ERP
ABAP
Business Warehousing
SAP Basis
Material Management
Sales & Distribution
Human Resource
Netweaver
Customer Relationship Management
Production and Planning
Networking Programming
Corba Tutorial
Networking Tutorial
Microsoft Office
Microsoft Word
Microsoft Outlook
Microsoft PowerPoint
Microsoft Publisher
Microsoft Excel
Microsoft FrontPage
Microsoft InfoPath
Microsoft Access
Accounting
Financial Accounting
Managerial Accounting
Computer Basics
Basics of Computer


Creating database applications in VB
Previoushome Next


Brief introduction to the usages of Access data bases

What I think is the most compelling thing about Visual Basic is it's easy way of modifying and accessing databases. This is what I think you should learn next and you will find many applications for this knowledge.Without using a database for data storage,i almost never make the program .

There are many ways to work with the databases in Visual Basic, and I would think you have at least glanced at the Data control and since it is so easy to use and too limited to be interesting for a professional developer,it will not even mention the Data control further in this text. (Ok, there are some exceptions to this.)

What I will teach you to use in this text is DAO (Data Access Objects) and you will get familiar with opening a database and adding/retrieving/deleting/updating records from tables. I will only use an Access Database (*.mdb) in my examples and since this is the most used DBMS (DataBase Management System) for smaller applications made in Visual Basic. We will at the end of this lesson have made a simple and yet functional, phone book application.




Database Object

The first thing you must do in your application is to open a database where your tables are stored and you need to declare a variable to hold your database in order to do this. This is done with following statement:

Dim dbMyDB As Database

This gives you a object/variable that can hold a reference to your database. To open a simple Access database named "MyDatabase.mdb" and do this:

Set dbMyDB = OpenDatabase("MyDatabase.mdb")

You should really specify the complete path to the db and if your current directory is the directory where the database is situated, this will work.

So, now you have opened a database and this won't give you any data. What you need to do is open a table in the database itself. You're not limited to open a single table and sometimes you have two or more tables that are related to each other and linked together w ith foreign keys, and there are ways to handle




RecordSet Object

To hold your table,Visual Basic uses an object called RecordSet. To declare such an object and to open the table, write the following statement:

Dim rsMyRS As RecordSet

Set rsMyRS = dbMyDB.OpenRecordSet("MyTable", dbOpenDynaset)

What happened there? Well, I declared a RecordSet object and used the Database object's OpenRecordSet method to open a table of type Dynaset and you can open a RecordSet in several modes. VB's online help file explains the different modes and what they ar e for. The Dynaset mode is the mode I use mostly and it gives you a RecordSet that you can add, delete and modify records in.




Accessing records

Now that we have opened a table (referred to as RecordSet from now on) we want to access the records in it and the RecordSet object allows us to move in it by using the methods MoveFirst, MoveNext, MovePrevious, MoveLast (among others). I will use some of these to fill up a list box with records of our RecordSet.

To get this example to work, make a database (with Access) called "MyDatabase.mdb" with the table "MyTable" in it and this table should have the fields "ID" of type "Counter" that you set to be the primary key, the field "Name" of type Text and a field "P hone" of type Text. Add some records to it and put a list box on a form and call it "lstRecords".

Dim dbMyDB As Database
Dim rsMyRS As RecordSet

Private Sub Form_Load()

Set dbMyDB = OpenDatabase("MyDatabase.mdb")
Set rsMyRS = dbMyDB.OpenRecordSet("MyTable", dbOpenDynaset)

If Not rsMyRS.EOF Then rsMyRS.MoveFirst
Do While Not rsMyRS.EOF
lstRecords.AddItem rsMyRS!Name
lstRecords.ItemData(lstRecords.NewIndex) = rsMyRS!ID
rsMyRS.MoveNext
Loop

End Sub



Searching the RecordSet

You might have wondered why I put the value of the field "ID" in the list box's ItemData property and i did this so that we would know the primary key for all the records in order to search for a record.

Put a text box somewhere on the form and call it "txtPhone". Then copy the following code to the project.

Private Sub lstRecords_Click()

rsMyRS.FindFirst "ID=" & Str(lstRecords.ItemData(lstRecords.ListIndex))
txtPhone.Text = rsMyRS!Phone

End Sub




Updating the Database

When doing database programming,you will probably want to be able to update some value of some field. This is done with Edit and Update and we will try to change the value of the "Phone" field by editing the text in the text box and clicking a button.

Put a command button on the form and name it "cmdUpdate". Then copy the following code to the project

Private Sub cmdUpdate_Click()

rsMyRS.Edit
rsMyRS!Phone = txtPhone.Text
rsMyRS.Update

End Sub



Deleting and Adding records
Deleting

Deleting records couldn't be simpler and to delete the current record you just invoke the Delete method of the RecordSet object. We will put this feature in our little project and make one more command button named "cmdDelete" and the following code will do the work of deleting our currently selected person.

Private Sub cmdDelete_Click()

rsMyRS.Delete
lstRecords.RemoveItem lstRecords.ListIndex

End Sub



Adding

Adding records is much like updateing, except you use AddNew instead of Edit and let's add one more command button to our application. Let's call it...errh...let me see...yea! "cmdNew" =). Here is the code which adds a new record.

Private Sub cmdNew_Click()

rsMyRS.AddNew
rsMyRS!Name = "A New Person"
lstRecords.AddItem rsMyRS!Name
lstRecords.ItemData(lstRecords.NewIndex) = rsMyRS!ID
rsMyRS!Phone = "Person's Phone Number"
rsMyRS.Update

End Sub

 Related Visual Basic Tutorial Books
A Visual Basic 6 Programmer's Toolkit
VB6 Reference Library
Practical Visual Basic 6
Learn VisualBasic
General Topics in VB
More Link » »
 
 Visual Basic Tutorial FAQs
Sorry No Records are Available
More Link » »
 
 Visual Basic Tutorial Interview Questions
what is visual basic?
What is MAPI?
What is early binding and late binding ?
WhatisOLEDB?
How many event in VB6 form.
More Link » »
 
 Visual Basic Tutorial Articles
Parsing and Sorting
Building Branching Structures
Implement Drag and Drop in Your Windows Forms Applications
What's New in Visual Basic 9.0
Visual Basic 2005 with .NET 3.0 Programmer's Reference
More Link » »
 
 Visual Basic Tutorial News
Publisher's description of Visual Basic 5.0 Runtime Module
Publisher's description of Visual Basic Database Projects
Exclusive Discount on uCertify’s 70-548 C# and VB Prepkits
More Link » »


Share And Enjoy:These icons link to social bookmarking sites where readers can share and discover new web pages.
  • blinkbits
  • BlinkList
  • blogmarks
  • co.mments
  • connotea
  • del.icio.us
  • De.lirio.us
  • digg
  • Fark
  • feedmelinks
  • Furl
  • LinkaGoGo
  • Ma.gnolia
  • NewsVine
  • Netvouz
  • RawSugar
  • Reddit
  • scuttle
  • Shadows
  • Simpy
  • Smarking
  • Spurl
  • TailRank
  • Wists
  • YahooMyWeb

Previoushome Next

Keywords: Creating database applications in VB, visual basic applications, visual basic database, how to database, vb source code, visual basic vb, vb ms access, visual basic net applications, microsoft access database, ms access database, asp net database, sql server database, connect to database, vb asp net, vb array, database tutorial, text creating, xml database, asp database, php database, c# database


HTML Quizes
HTML Quiz
XHTML Quiz
CSS Quiz
TCP/IP Quiz
CSS 1.0 Quiz
CSS 2.0 Quiz
XML Quizes
XML Quiz
XSL Quiz
XSLT Quiz
DTD Quiz
Schema Quiz
XForms Quiz
XSL-FO Quiz
XML DOM Quiz
XLink Quiz
XQuery Quiz
XPath Quiz
XPointer Quiz
RDF Quiz
SOAP Quiz
WSDL Quiz
RSS Quiz
WAP Quiz
Web Services Quiz
Browser Scripting Quizes
JavaScript Quiz
VBScript Quiz
DHTML Quiz
HTML DOM Quiz
WMLScript Quiz
E4X Quiz
Server Scripting Quizes
ASP Quiz
PERL Quiz
SQL Quiz
ADO Quiz
CVS Quiz
Python Quiz
Apple Script Quiz
PL/SQL Quiz
SQL Server Quiz
.NET (dotnet) Quizes
Microsoft.Net Quiz
ASP.Net Quiz
.Net Mobile Quiz
C# : C Sharp Quiz
ADO.NET Quiz
VB.NET Quiz
VC++ Quiz
Multimedia Quizes
SVG Quiz
Flash Quiz
Media Quiz
SMIL Quiz
Photoshop Quiz
Gimp Quiz
Matlab Quiz
Gnuplot Programming Quiz
GIF Animation Quiz
Scientific Visualization Quiz
Graphics Quiz
Web Building  Quizes
Web Browsers Quiz
Web Hosting Quiz
W3C Quiz
Web Building Quiz
Web Quality Quiz
Web Semantic Quiz
Web Careers Quiz
Weblogic Quiz
SEO Quiz
Web Site Hosting Quiz
Domain Name Quiz
Java Quizes
Java Quiz
JSP Quiz
Servlets Quiz
Struts Quiz
EJB Quiz
JMS Quiz
JMX Quiz
Eclipse Quiz
J2ME Quiz
JBOSS Quiz
Programming Langauges Quizes
C Quiz
C++ Quiz
Visual Basic Quiz
Data Structures Using C Quiz
Cobol Quiz
Assembly Language Quiz
Mainframe Quiz
Forth Programming Quiz
Lisp Programming Quiz
Pascal Quiz
Delphi Quiz
Fortran Quiz
Oops Quiz
Data Ware Housing Quiz
CGI Programming Quiz
Emacs Quiz
Gnome Quiz
ILU Quiz
Soft Skills Quizes
Communication Skills Quiz
Time Management Quiz
Project Management Quiz
Team Work Quiz
Leadership Skills Quiz
Corporate Communication Quiz
Negotiation Skills Quiz
Database Quizes
Oracle Quiz
MySQL Quiz
Operating System Quizes
BSD Quiz
Symbian Quiz
Unix Quiz
Internet Quiz
IP-Masquerading Quiz
IPC Quiz
MIDI Quiz
Software Testing Quizes
Testing Quiz
Firewalls Quiz
SAP Module Quizes
ERP Quiz
ABAP Quiz
Business Warehousing Quiz
SAP Basis Quiz
Material Management Quiz
Sales & Distribution Quiz
Human Resource Quiz
Netweaver Quiz
Customer Relationship Management Quiz
Production and Planning Quiz
Networking Programming Quizes
Corba Quiz
Networking Quiz
Microsoft Office Quizes
Microsoft Word Quiz
Microsoft Outlook Quiz
Microsoft PowerPoint Quiz
Microsoft Publisher Quiz
Microsoft Excel Quiz
Microsoft FrontPage Quiz
Microsoft InfoPath Quiz
Microsoft Access Quiz
Accounting Quizes
Financial Accounting Quiz
Managerial Accounting Quiz
Computer Basics Quizes
Basics of Computer Quiz
Copyright © 2008. Academic Tutorials.com. All rights reserved Privacy Policies | About Us
Our Portals : Academic Tutorials | Best eBooksworld | Beyond Stats | City Details | Interview Questions | Discussions World | Excellent Mobiles | Free Bangalore | Give Me The Code | Gog Logo | Indian Free Ads | Jobs Assist | New Interview Questions | One Stop FAQs | One Stop GATE | One Stop GRE | One Stop IAS | One Stop MBA | One Stop SAP | One Stop Testing | Quick2Host | Quick2Host Mirror | Quick Site Kit | Sirf Dosti | Source Codes World | Tasty Food | Tech Archive | Testing Interview Questions | Tests World | The Galz | Top Masala | Vyom | Vyom eBooks | Vyom International | Vyom Links | Vyoms | Vyom World
Copyright © 2003-2008 Vyom Technosoft Pvt. Ltd., All Rights Reserved.