Hello friends, in this
blog we are going to study how to connect Oracle database with
Microsoft’s Visual Basic. To do it we must have installed Oracle
and Visual Basic (VB). If it is not installed then please get it
install. Now to connect VB with Oracle, Oracle must contain at least
one table. Further process is explained step by step:
Design form in VB as
shown in figure, form must contain one text box box for each field in
table in Oracle.
- Design form in VB as shown in figure, form must contain one text box box for each field in table in Oracle.
- You have to add component in VB: right clicking on toolbox select option component, it will display new window containing three fields. From these three fields select “Controls” and from them select component named “Microsoft ADO data control(OLEDB)” then apply it then click on OK as shown in figure 1. It will add new component in tool box.
Figure1.Adding
ADODC component
|
-
Click on this control and put it on form as shown in figure 2.
Figure2. Form design and ADODC control |
-
Now open control panel
from start button select administrative tool, it will display list
from them select “Data source (ODBC)”. It will display ODBC data
source administrator window shown in figure 3.
Figure 3. Creating Data source - From that click on add button it will display new window for creating new data source.
- From that select your database which is installed previously that is Oracle. I have installed Oracle XE that’s why I am selecting it as shown in figure 3.
-
After that it will
display configuration window where you can specify data source name
and you can test connection by clicking on test button. For testing
connection it will ask for service name, user name and password which
is of we have set to oracle. And after that click on OK button it
will display message “connection successful” as shown in figure
4.
Figure 4 Configuring data source
- Now come to VB right click on ADODC control and select properties, it will display new window. From that window select second option “Use ODBC data source name” from general tab. From that select data source name which is created previously from administrative tool as shown in figure 5.
- Now click on second tab “Authentication” in that enters user name and password provided to Oracle as shown in figure 5.
- Now come to third tab “Record source”, in that enter query which you want to perform. I am entering select as shown in figure, and then click on apply and then OK as shown in figure 5.
Figure 5 ADODC component property
- Now click on text box
and go to property and click on Data source as ADODC which is already
there and Data field which data you want to display in that text box.
Do this for all text box as shown in figure 6.
Figure 6 Property window of text box
Figure7.Run project
thanks alot !
ReplyDeletei was in need of this :)