0% found this document useful (0 votes)
68 views

Visual Basic Guide

This document provides steps for connecting a Visual Basic application to an Oracle database using ADO (ActiveX Data Objects). It describes adding an ADO control to the form, configuring it to connect to Oracle using a username and password, and writing code to open a recordset and retrieve and display data from a table. It also includes code examples to navigate the recordset, retrieve field values, and insert a new record into the table.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
68 views

Visual Basic Guide

This document provides steps for connecting a Visual Basic application to an Oracle database using ADO (ActiveX Data Objects). It describes adding an ADO control to the form, configuring it to connect to Oracle using a username and password, and writing code to open a recordset and retrieve and display data from a table. It also includes code examples to navigate the recordset, retrieve field values, and insert a new record into the table.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

Visual Basic

Database connectivity

Steps
Start Programs Microsoft Visual Studio Microsoft Visual Basic File New project StandardEXE Place the required controls in the form.

Steps

Steps
Add ADO control thro Project Components

Steps
Add the ADODC control to form.

Steps
Right click on the control properties Build ADODC

Steps
Now select provider for Oracle

Steps
Enter username and password Connection OK Test

Steps
Copy the Connection String and use it while coding

Steps
Write coding for each command button

Code
Dim con As ADODB.Connection Dim rs As New ADODB.Recordset Private Sub Form_Load() Set con = New ADODB.Connection Set rs = New ADODB.Recordset con.Open ("Provider=MSDAORA.1;User ID=scott;Password=tiger;Persist Security Info=False") rs.Open "select * from dept", con, adOpenDynamic, adLockOptimistic Text1.Text = rs("deptno") Text2.Text = rs("dname") Text3.Text = rs("loc") End Sub Underlined text is the connection String copied .. Type password manually.. Now the ADODB control in form can be removed

Code
Private Sub Command3_Click() rs.MoveFirst Text1.Text = rs("deptno") Text2.Text = rs("dname") Text3.Text = rs("loc") End Sub Private Sub Command4_Click() rs.MoveLast Text1.Text = rs("deptno") Text2.Text = rs("dname") Text3.Text = rs("loc") End Sub

Code
Private Sub Command3_Click() rs.MoveFirst Text1.Text = rs("deptno") Text2.Text = rs("dname") Text3.Text = rs("loc") End Sub Private Sub Command4_Click() rs.MoveLast Text1.Text = rs("deptno") Text2.Text = rs("dname") Text3.Text = rs("loc") End Sub

Code
Private Sub Command5_Click() Set con = New ADODB.Connection Set rs = New ADODB.Recordset con.Open ("Provider=MSDAORA.1;User ID=scott;Password=tiger;Persist Security Info=False") rs.Open "insert into dept values(" & Text1.Text & ",'" & Text2.Text & "','" & Text3.Text & "')", con, adOpenDynamic, adLockBatchOptimistic con.Close MsgBox "record inserted" End Sub

You might also like