ARTICLE

How to Connect Oracle Databse with VB.Net

Posted by Brijesh Jalan Articles | ADO.NET in VB.NET August 02, 2010
In this article we will learn how to connect oracle database with VB.Net
Reader Level:

Step to connect Oracle Databse with VB.Net

  1. Create a new project in Visual Studio 2010 using VB.NET.
  2.  
  3. Add the following assembly in the Default.aspx.cs.

    Imports
    System.Data.OleDb
  4. Now Add Some Labels, textboxes and button on Default.aspx page

    <asp:LabelID="Label1"runat="server"Text="Name"></asp:Label>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
           <asp:TextBoxID="TextBox1"runat="server"></asp:TextBox>
            <br/>
            <br/>
            <asp:LabelID="Label2"runat="server"Text="Address"></asp:Label>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
           <asp:TextBoxID="TextBox2"runat="server"></asp:TextBox>
            <br/>
            <br/>
            <asp:LabelID="Label3"runat="server"Text="Age"></asp:Label>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
           <asp:TextBoxID="TextBox3"runat="server"></asp:TextBox>
            <br/>
            <br/>
            <asp:LabelID="Label4"runat="server"Text="Phone_no"></asp:Label>
    &nbsp;&nbsp;&nbsp;&nbsp;
           <asp:TextBoxID="TextBox4"runat="server"></asp:TextBox>
            <br/>
            <br/>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
           <asp:ButtonID="Button1"runat="server"onclick="Button1_Click"Text="Button"/>

  5. Now create connection with Oracle using oledb.

    PartialClass _Default
        Inherits System.Web.UI.Page
        Dim con As OleDbConnection
        Dim cmd As OleDbCommand
       Dim str AsString

    In this the user id and password is Oracle SQL+ user id and password and database is the orcl (It is the Bydefault database).

  6. Click On Button and insert the data into the Oracle database table.

    ProtectedSub Button1_Click(ByVal sender As Object, ByVal eAs System.EventArgs)Handles Button1.Click
            con = New OleDbConnection("Provider =MSDAORA.1;User ID =system; Password =sys123;database=orcl")
            con.Open()
            str = ((("insert into emp1 values('" + TextBox1.Text & "','") + TextBox2.Text & "','") + TextBox3.Text & "','") + TextBox4.Text & "')"
            cmd = New OleDbCommand(str, con)
            cmd.ExecuteNonQuery()
         
    End Sub

    OUTPUT OF THE APPLICATION:

    output-oracle-database-conn.jpg
    Oracle Database connection Output

    output.jpg

    The name Alicia is successfully inserted into the oracle database.

Login to add your contents and source code to this article
share this article :
post comment
 

i am making a project on asp.net with visual basic 2010 n oracle 11g database ....i just wanted to know how to connect/ insert data in vb textbox so that it gets saved in oracle table.... my codings areVISUAL BASIC 2010 :".........<%@ Page Language="VB" AutoEventWireup="false" CodeFile="customer identification.aspx.vb" Inherits="customer_identification" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"><title></title><style type="text/css">.style1{width: 1189px;font-family: Broadway;color: #FFFFFF;font-size: xx-large;text-align: center;}.style2{height: 261px;width: 1187px;}.style5{width: 1189px;color: #FFFFFF;height: 28px;margin-top: 15px;text-align: center;}.style11{color: #FFFFFF;}.style13{text-align: left;font-family: "Britannic Bold";font-size: xx-large;color: #FF3300;text-decoration: underline;width: 1186px;}.style14{text-align: center;}.style15{font-size: 40pt;}.style16{width: 1185px;}.style17{width: 1186px;}.style18{width: 1187px;}.style19{width: 1188px;}.style20{color: #FFFFFF;width: 1185px;}.style21{width: 1186px;color: #FFFFFF;}</style> </head> <body background="images/vista_wallpapers%20(27).jpg"><form id="form1" runat="server"><div class="style1"><div><asp:Image ID="Image1" runat="server" Height="186px" ImageUrl="~/images/Presentation1.jpg" Width="1191px" /></div><br /><div style="background-image: url('images/wallpaper_1019.jpg')"><span class="style15">CUSTOMER IDENTIFICATION</span></div></div><div class="style2" style="background-image: url('images/MEGA1.jpg')"></div><a href="javascript:__doPostBack('LinkButton1','')">    </a><div><div class="style5" style="background-image: url('images/vista_wallpapers (27).jpg')"> <a href="javascript:__doPostBack('LinkButton1','')"><asp:LinkButton ID="LinkButton10" runat="server" CssClass="style11" PostBackUrl="~/Default.aspx">HOME</asp:LinkButton></a> | <asp:LinkButton ID="LinkButton1" runat="server" BorderStyle="None" CssClass="style11" PostBackUrl="~/customer identification.aspx">CUSTOMER IDENTIFICATION</asp:LinkButton>  | <asp:LinkButton ID="LinkButton2" runat="server" CssClass="style11" PostBackUrl="~/downloading.aspx">DOWNLOADING</asp:LinkButton>  |<asp:LinkButton ID="LinkButton3" runat="server" CssClass="style11" PostBackUrl="~/Printing.aspx"> PRINTING</asp:LinkButton>  | <asp:LinkButton ID="LinkButton4" runat="server" CssClass="style11" PostBackUrl="~/Photocopy.aspx">PHOTOCOPY</asp:LinkButton>  | <asp:LinkButton ID="LinkButton5" runat="server" CssClass="style11" PostBackUrl="~/Lamination.aspx">LAMINATION</asp:LinkButton>  | <asp:LinkButton ID="LinkButton6" runat="server" CssClass="style11" PostBackUrl="~/spiralbinding.aspx">SPIRAL BINDING</asp:LinkButton>  | <asp:LinkButton ID="LinkButton7" runat="server" CssClass="style11" PostBackUrl="~/buyingitems.aspx">BUYING  ITEMS</asp:LinkButton>  | <asp:LinkButton ID="LinkButton8" runat="server" CssClass="style11" PostBackUrl="~/photoprint.aspx">PHOTO PRINT</asp:LinkButton>  |<asp:LinkButton ID="LinkButton9" runat="server" CssClass="style11" PostBackUrl="~/fax.aspx">FAX</asp:LinkButton></div></div><p class="style16"><span class="style11">Cr. SL.NO              :      </span><asp:TextBox ID="TextBox1" runat="server" Width="93px"></asp:TextBox><span class="style11">                                               CABIN NO        :     </span><asp:DropDownList ID="DropDownList1" runat="server"></asp:DropDownList><span class="style11">                                  PURPOSE OF WORK     :         </span><asp:DropDownList ID="DropDownList5" runat="server"></asp:DropDownList></p><p class="style17"><span class="style11">NAME                    :      </span><asp:TextBox ID="TextBox7" runat="server" Width="934px"></asp:TextBox></p><p class="style17"><span class="style11">ADDRESS              :      </span><asp:TextBox ID="TextBox4" runat="server" Width="937px"></asp:TextBox></p><p class="style21">LOG IN TIME        :      <asp:TextBox ID="TextBox9" runat="server" Width="201px"></asp:TextBox>                LOG OUT TIME :           <asp:TextBox ID="TextBox10" runat="server" Width="192px"></asp:TextBox>           DATE :     <asp:TextBox ID="TextBox11" runat="server" Width="207px"></asp:TextBox></p><p class="style18"><span class="style11">CUSTOMER IDENTIFICATION CARD :  </span><asp:DropDownList ID="DropDownList3" runat="server"></asp:DropDownList><span class="style11">                                         CARD NUMBER :  </span><asp:TextBox ID="TextBox5" runat="server" Width="442px"></asp:TextBox><span class="style11">     </span></p><p class="style19"><span class="style11">MOBILE NUMBER :    </span><asp:DropDownList ID="DropDownList4" runat="server"></asp:DropDownList><span class="style11">  </span><asp:TextBox ID="TextBox6" runat="server" Width="200px"></asp:TextBox><span class="style11">                    COUNTRY           : <asp:TextBox ID="TextBox8" runat="server" Width="439px"></asp:TextBox></span></p><p class="style14"><span class="style11">I agree to the rules written below     </span><asp:RadioButton ID="Agree" runat="server" CssClass="style11" /><span class="style11">     I disagree to the rules written below </span><asp:RadioButton ID="Disagree" runat="server" CssClass="style11" /></p><p class="style14"><asp:Button ID="Button1" runat="server" Text="Insert" />     <asp:Button ID="Button2" runat="server" Text="Delete" /></p><p class="style14"> </p></form><div class="style13" style="background-image: url('images/wallpaper_1019.jpg')"><em>RULES :</em></div><p class="style20">WRITE ABOUT RULES BRING FROM CYBER</p> </body> </html> ..............."ORACLE TABLE "........... CREATE TABLE "HR"."CUSTOMERID" ( "CSL.NO" NUMBER NOT NULL ENABLE, "CABIN NO" NUMBER NOT NULL ENABLE, "PURPOSE" VARCHAR2(50 BYTE) NOT NULL ENABLE, "NAME" VARCHAR2(50 BYTE) NOT NULL ENABLE, "ADDRESS" VARCHAR2(200 BYTE) NOT NULL ENABLE, "DATE" DATE DEFAULT NULL NOT NULL ENABLE, "CUSTOMER ID CARD" VARCHAR2(100 BYTE) NOT NULL ENABLE, "CARD NO" VARCHAR2(100 BYTE) NOT NULL ENABLE, "MOBILE NO" NUMBER, "COUNTRY" VARCHAR2(30 BYTE) NOT NULL ENABLE, "LOGIN TIME" TIMESTAMP (6) NOT NULL ENABLE, "LOGOUT ITME" TIMESTAMP (6) NOT NULL ENABLE, CONSTRAINT "CUSTOMERID_PK" PRIMARY KEY ("CSL.NO")USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)TABLESPACE "USERS" ENABLE) SEGMENT CREATION IMMEDIATE PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGINGSTORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)TABLESPACE "USERS" ;COMMENT ON COLUMN "HR"."CUSTOMERID"."DATE" IS 'TO_DATE(''15-NOV-05 10:56 A.M.'',''DD-MON-YY HH:MI A.M.'')';........."I have connected the table with visual basic but dont know how to insert ... i mean where to write the codings or what to write so that it will be saved...thanx

Posted by crismic paul May 01, 2012

i'm not sure about how to connect from VB to Oracle? Is it like connect to Database?

Posted by sovan nara Jan 04, 2011
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
Become a Sponsor