Thursday, March 24, 2011

Connect Oracle Database using Visual Basic



'How to connect Oracle Database from Visual Basic
'Sample code and connection strings to connect Oracle using Visual Basic:

Dim conn As ADODB.Connection

' Open a Conn_Dataection using Oracle ODBC.
Set Conn_Data = New ADODB.Connection
Conn_Data.ConnectionString = "Driver={Microsoft ODBC for Oracle};" & "UID=user_name;PWD=user_passsword"
Conn_Data.Open

'Open the table as in:

Dim rs_Data As ADODB.Recordset

' Open the table.
Set rs_Data = New ADODB.Recordset
rs_Data.Open "TableName", Conn_Data, adOpenDynamic, adLockOptimistic, adCmdTable

'Enter the user name password and table name as per the database.
'it must be valid one.

'To reads the data from the table and displays the values in a ListBox

' List the data.
Do While Not rs_Data.EOF
    txt = ""
    For Each fld In rs_Data.Fields
        txt = txt & Trim$(fld.Value) & ", "
    Next fld
    If Len(txt) > 0 Then txt = Left$(txt, Len(txt) - 2)
    List1.AddItem txt
    rs_Data.MoveNext
Loop

'Finally close the recordset and close the Conn_Dataection:
rs_Data.Close
Conn_Data.Close

23 comments:

ecommerce website development said...

Well you have great code here that will be very useful for me.. I will implement this and try out.. I often visit your blogs as you share some good some and I love to learn more on VB.

sap project systems said...

I love to visit your blog as I do find so many useful source codes that support me when developing applications. I have implemented the above one too and is able to successfully connect the database using Visual Basic. Thanks

Kamran Qadri said...

Hi,

What if when you want the specified data from table like the date range or some thing...

It is very helpfull for me for my project...

Rijz said...
This comment has been removed by the author.
Rijz said...

hi. am beginner in oracle and visual basic. I have installed VB 2008 and oracle 11g express edition. My OS is windows 7, i want to know how to connect the oracle from visual basic??? Can u please help me out. I dont find Microsoft OLE DB Provider for Oracle (Database Engine) driver to change the database connection in VB. How can i install n hw can i knw that it is already installed in ma system or not. And i tried using the above code n failed may be because i went wrong some where. How can i resolve this??

kisuule Ivan said...

Hi,thanks so much for the great code,i have a task to accomplish and the task is to extract data from an sql server database to oracle,i'd like to accomplish this task using a vb solution.please any code that can help me in this regard is highly welcomed.

Thanks
John

Anonymous said...

HI

Anonymous said...

Hi
I am not able to connect oracle database still. could you please, guide me?

Web Designers Pitampura said...

Blogging is the new poetry. I find it wonderful and amazing in many ways.

misindia said...

Thanku for sharing this article. Set in the flawless slopes of South Mussoorie. MIS, Best Boarding School For Girls has a rich history and was laid out in 1984. Arranged only 33 km away from the capital city Dehradun, this unspoiled grounds is encircled by the appeal of nature, with its air improved by pine, deodar, and other coniferous trees. Laid out to make worldwide residents who can get through any conceivable trial of life through training, MIS sustains sure pioneers furnished with common information and inward harmony. The school educational program sticks to global principles and the greatest guidance guarantees that understudies are prepared to have adjusted existences.

misindia said...

Education at international boarding schools for girls in India also includes the development of ethics and morality, which are important in the professional realm. It is also critical to a country's progress. If a country has both financial and human resources, but no human resources to use the financial resources effectively, development falls over the cliff. Schooling has an influence on both an individual's and a country's growth and development.

SerendipityRüya11 said...

düzce evden eve nakliyat
denizli evden eve nakliyat
kırşehir evden eve nakliyat
çorum evden eve nakliyat
afyon evden eve nakliyat
Xİ63FB

Seekware Global Bunbury said...

Discover bespoke software solutions crafted specifically for your Bunbury-based business with Seekware Global. Our expert team specializes in custom software development, addressing unique operational needs and challenges faced by local enterprises. Whether it's streamlining processes, enhancing productivity, or creating innovative tools, we tailor comprehensive software solutions that align perfectly with your business objectives. Partner with us to leverage cutting-edge technology and propel your Bunbury business towards unparalleled growth and success.

UEEPHONE iPads Wholesale Service said...

UEEPHONE is an iPad wholesale distributor since 2012! We sell to small retailers, repair shops, wholesalers, refurbishes, and smaller distributors around the globe. High-quality iPads are shipped worldwide, and a drop shipping service is provided. Our iPads are precisely graded based on their performance and condition. The iPad wholesale price is set based on the real quality of our product and service to guarantee our customers that every penny you spent does worth it.

Low Voltage Switchgear said...

Whatoop Low Voltage Switchgear is a high-quality electrical distribution and control device designed to provide reliable and safe power distribution and control in low voltage systems. It is suitable for a wide range of industrial, commercial, and residential applications.

Linkotest Drop Test Machine said...

A drop test machine is used to test the damage caused by dropping the product package and to evaluate the impact strength during transportation and handling. Our drop testers are used for the purpose of dropping tests while keeping the attitude of the specimen and investigating its effect. In addition, it can be used not only for electricity and electronics but also for drop tests in various fields such as medicine, food, and pharmaceutical. Linkotest has proudly served the drop test industry with mechanical drop testers for mobile products, rotating drum testers, drop testers for packages, and all types of drop testers for large items for over 23 years.

Custom Tube Gift Box Manufacturer said...

As a professional tube gift box manufacturer with over 12 years of experience, Hopak provides a remarkable array of custom gift box solutions with extraordinary printing quality. A tube gift box is a great tool to impact your brand. We come up with innovations in gift packaging with your requirements or design ideas. Hopak utilizes high-quality printing to make an attractive display for your packaging tube. It helps to make your brand more identified in the market and your products more memorable.

Stand Up Pouch Manufacturer from China said...

Stand up pouch Manufacturer are flexible and lightweight, which makes them more cost-effective to transport and store compared to rigid packaging. And have a larger surface area for branding and product information, making them great for marketing. Stand up pouches can be made from various materials, including recyclable and biodegradable options, making them more environmentally friendly. The design of stand-up pouches allows them to be easily displayed on store shelves and improves product visibility.

Flexible Safety Barriers said...

As a professional safety barrier manufacturer in China, Aotons provides two types of flexible safety barriers to reduce the risk of accidents, damage, and unscheduled downtime. One is the AEGIS safety barrier, which is made of AEGIS steel material, it is usually used as a parking barrier. Another is the ARMORFLEX® safety barrier, which is made of ARMORFLEX® material independently developed by our company, it is used as an industrial safety barrier. Aotons flexible safety barrier is the most durable and advanced flexible workplace barrier on the market, now it has been used by many brand companies, like Mengniu, Yili, TNT, DHL, BMW, Mercedes Benz, Volkswagen, P & G, etc.

Top 20 Bollard Manufacturers in 2023 said...

Bollards, also known as car, stops, are a type of bay that is defined as a “fence or barrier in the roadway.” They are usually shaped like cylindrical columns and installed perpendicular to the ground. Bollards are usually installed at intersections, crosswalk connections, or intersection openings to prevent casualties. Install bollards to prevent vehicles from driving onto the sidewalk in the unlikely event that they do. In the previous article, we mentioned a lot of knowledge about bollards. So, in today’s guide, we will educate you on the top twenty bollard manufacturers in 2023

Top 15 Guardrail Manufacturers in 2023 said...

A guardrail is a protective device (pole, safety fence, etc.) used to prevent or mitigate damage caused by vehicle collisions within a factory. Many manufacturing plants are operated by forklifts, AGVs, and other vehicles. If these vehicles come into contact with workers or production equipment, serious industrial accidents and shutdowns can occur. In today’s guide, we will introduce you to the top 15 guardrail manufacturers of 2023. Read on to learn more.

Paint Protection Film Noida said...

Active Detailing sets the standard for Paint protection film services in Noida and Indirapuram.

AppGenAI a Modern Mobile Apps Creator said...

App GenAI is the World’s First and most Powerful AI-driven, Drag-N-Drop App Builder that Creates Unlimited iOS & Android Mobile Apps in less than 2 minutes. Now we can build, customize & launch our dream Apps. Using it we can create thousands of premium DFY templates in multiple Niches

Post a Comment

 
Powered by Blogger