Visual Basic uses OLE automation to access Oracle databases

Source: Internet
Author: User
Oracle oo4o
Recently, this project is VB.net and Oracle. Because of the customer's requirements, Oracle provides oo4o instead of traditional ODBC. The full name is Oracle Objects for OLE (oo4o ). According to Japanese data, this is the most efficient and is recommended. However, ODBC is recommended for English and Chinese. No matter who you are. Write down how to use and the result.
The connection speed obtained through the test is as follows: the speed of inserting or modifying a record is about 1 hour, with an average of 10 thousand records per minute, and a record is about 167 seconds.
Oo4o must be installed first and downloaded here
Http://www.oracle.com/technology... dows/OLE/index.html
This is useful. There is still a lot of information on the official website.
After installation, see Oracle INPRO server XXXXX Type Library in VB.net. The intermediate Xxxxx is the version number.
Oracleinprocserver can be seen in project reference
Related Classes:
Orasession session
Oradatabase
Oradynaset dynamic set
The program is as follows:
Imports oracleinprocserver

Private shared objorasess as orasession
Private shared objoradb as oradatabase
Private shared data as oradynaset

Database Connection
1) Create an oracle session
Objorasess = Createobject ("oracleinprocserver. xorasession ")
2) connect to the database
Objoradb = objorasess. opendatabase (Oracle server name, username & "/" & password, 0 &)
Note: the Oracle server name is the TNS name you set in the Oracle listener.
Opendatabase cannot be found. Only remember.
All subsequent operations will be performed by connecting to the database objects. You can directly view the definition and help to find it.
Here we will talk about the wrong storage location. When the objects connected to the database are not created, errors are stored in properties such as lastservererrtext (error message) of the session object. When SQL is executed, the connected database object has been created and stored in its lastservererrtext attribute. The Session Object Property has no content.
SQL statement execution Method
Objoradb. executesql (SQL)
Retrieval Method
Data = objoradb. dbcreatedynaset (SQL, 0) Note: The dbcreatedynaset method cannot be directly found in VB.net.
The function of this dynamic set is incomparable with the powerful function of the datatable. However, there are many basics. The search result is. findfirst. The column name is. fieldname (column index), and the column value is. Fields (column index or column name). value. Note that this value cannot be found, but it can be used or used, and the size is not sensitive .. Delete can be deleted, appended, modified, or copied. And the number of records in the current status.
For example:
Dim icount as integer
Dim icolloop as integer
Dim irowloop as integer
Dim data as oradynaset
Dim Drow as datarow
Dim tquarytable as datatable

Tquarytable = new datatable
Data = objoradb. dbcreatedynaset ("select * From XXXXX", 0)
Create offline data table
Icount = data. Fields. Count
For icolloop = 0 to icount-1
Tquarytable. Columns. Add (New datacolumn (data. fieldname (icolloop )))
Next
Irowloop = 0
Append content
While not data. EOF
Drow = tquarytable. newrow ()
For icolloop = 0 to icount-1
Drow. Item (icolloop) = gf_null2sp (data. Fields (icolloop). value)
Next
Tquarytable. Rows. Add (Drow)
Irowloop = irowloop + 1
Data. movenext ()
End while

Tquarytable is a datatable. This is to transfer the content of the dynamic set to the offline data table able.

Note that after you reinstall oo4o, the imports oracleinprocserver may have no namespace error. If the reference is correct. Delete the OBJ and bin directories to solve the problem. Otherwise, you cannot find the cause.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.