Saturday, April 25, 2009

Connect to Oracle Database from Visual Basic 6


Hi friends don’t worry to connect oracle and vb its simple just follow these instructions.


Step1:create a table in oracle

For ex:create table with name book

Insert some values in it

Close the oracle.

NOTE: don’t close oracle by pressing close button

Type ‘exit’ to close

Step2:Open VB and do the following

To add a reference, select Project-References from the Visual Basic Menu Bar


To add a components, select component from the Visual Basic Menu Bar







Tool box looks like this shown below







Drag and drop this in form

Now form looks like this shown below






















Double click the form(not at datagrid control) and paste the given code in form load event

Note :1)type ur userID and ur Password at 6th line in code.

2)Provider=in some systems it will be msdaora or MSDAORA.1

Dim oconn As New ADODB.Connection

Dim rs As New ADODB.Recordset

Dim strSQL As String

strSQL = "SELECT * FROM BOOK "note:give ur table name”

Set oconn = New ADODB.Connection

oconn.Open "Provider=msdaora;User Id=type ur userid;Password=type ur password;" “note:type ur userID and Password here”

rs.CursorType = adOpenStatic

rs.CursorLocation = adUseClient

rs.LockType = adLockOptimistic

rs.Open strSQL, oconn, , , adCmdText

Set DataGrid1.DataSource = rs

After pasting this just run the application.Now u can view ur table in datagrid like this






















IF U ARE NOT GETTING THE OUTPUT

CONTACT: M.VINOTH KUMAR

IT-B SEC

VELAMMAL ENGINEERING COLLEGE

PH.NOà9283205157

vinothkumarmadan@gmail.com

No comments:

Post a Comment