0% found this document useful (0 votes)
31 views1 page

DB Connectivity

This VBA code opens a connection to an Oracle database using a connection string, executes a SQL query to select data from an emp table, and loads the results into a data grid control on a form. It also shows how to commit transactions and optionally insert new records into a table.

Uploaded by

brahmi109
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views1 page

DB Connectivity

This VBA code opens a connection to an Oracle database using a connection string, executes a SQL query to select data from an emp table, and loads the results into a data grid control on a form. It also shows how to commit transactions and optionally insert new records into a table.

Uploaded by

brahmi109
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Private Sub Command1_Click()

Dim conn As New ADODB.Connection ‘( declaring the object as connection object )


Dim rs As New ADODB.Recordset ‘( declaring the object as recordset object )
Dim strSQL As String
strSQL = “select * from emp"
Set conn = New ADODB.Connection ‘( creating new connection )
conn.Open "Provider=OraOLEDB.Oracle.1;Password=tiger;Persist Security Info=True;User ID=system"
‘(Opening the connection if you are using ORACLE 10g )
rs.CursorType = adOpenStatic
rs.Open strSQL, conn ‘( reading the data from database and store it in a “record set” )
Set DataGrid1.DataSource = rs ‘( sending the that data into data grid )
conn.Execute ("commit") ‘( If we want to execute any SQL command we can use it )
‘conn.Execute ("insert into employees values(seq_no.nextval,'" & Text1.Text & "')")
'oconn.Execute ("create table siva ( frnds varchar2(15))")
oconn.Execute ("commit")
rs.Close
rs.Open strSQL, oconn
Set DataGrid1.DataSource = rs
End Sub

*********

conn.Open "Provider=OraOLEDB.Oracle.1;Password=tiger;Persist Security Info=True;User ID=system"


The red marked string is called connection string. If the above string is not working....
then copy the “connection string” after build the string mentioned in
http://www.johnsmiley.com/cis18/Smiley003.pdf

To add data-grid to the form:


Project  components  Microsoft data grid control 6.0  ok

Reference:
http://www.w3schools.com/ADO/ado_ref_connection.asp
http://support.microsoft.com/kb/308047
http://www.vb-helper.com/howto_ado_insert_into.html
http://www.johnsmiley.com/cis18/Smiley004.pdf

You might also like