How to Connect Oracle Database with VB.NET

In this article we will learn how to connect oracle database with VB.Net
  • 17659
 

Step to connect Oracle Databse with VB.NET

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

    Imports
    System.Data.OleDb
  3. 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"/>
     

  4. 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).
     

  5. 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

    oracle-database-connection.jpg
     

    The name Alicia is successfully inserted into the oracle database.

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.