How to Connect Oracle Database with VB.NET
In this article we will learn how to connect oracle database with VB.Net
Step to connect Oracle Databse with VB.NET
- Create a new project in Visual Studio 2010 using VB.NET.
- Add the following assembly in the Default.aspx.cs.
Imports System.Data.OleDb
-
Now Add Some Labels, textboxes and button on Default.aspx page
<asp:LabelID="Label1"runat="server"Text="Name"></asp:Label>
<asp:TextBoxID="TextBox1"runat="server"></asp:TextBox>
<br/>
<br/>
<asp:LabelID="Label2"runat="server"Text="Address"></asp:Label>
<asp:TextBoxID="TextBox2"runat="server"></asp:TextBox>
<br/>
<br/>
<asp:LabelID="Label3"runat="server"Text="Age"></asp:Label>
<asp:TextBoxID="TextBox3"runat="server"></asp:TextBox>
<br/>
<br/>
<asp:LabelID="Label4"runat="server"Text="Phone_no"></asp:Label>
<asp:TextBoxID="TextBox4"runat="server"></asp:TextBox>
<br/>
<br/>
<asp:ButtonID="Button1"runat="server"onclick="Button1_Click"Text="Button"/>
-
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).
-
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:

Oracle Database connection Output

The name Alicia is successfully inserted into the oracle database.