Connect to Oracle in ASP.NET

Working with oracle: 

Oracle instaliation comes with default login 

Username-scott 

Password-tiger

 

Start->programs->oracle->application development->select sql * plus 

Sql->create table loan(loantype varchar(20), roi number);

 

Inserting records into loan table: 

Sql>insert into loan values(‘&loantype’,roi); 

      Enter loantype:education 

      Enter      roi      :4

 

Sql>/ Enter loantype:education 

      Enter      roi      :10

 

Sql>/ Enter loantype:education 

      Enter      roi      :14

 

Sql>exit

 

Creating website to connect with oracle database using oledb.net 

Goto visual studio 

Start->run->devenv

 

It will display main window of visual studio 

File menu->new->website->visual c#->select asp.net empty website 

Weblocation->e:\aspnet\obcsite[drive:\dir\websitename] 

Visual studio create a folder with website name, in this folder website related files will be placed

 

Add webform 

Goto view menu and select solution explorer 

Right click on website path and select add new item 

Select webform 

Give name as default.aspx  

 

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> 

<!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> 

</head> 

<body> 

    <form id="form1" runat="server"> 

    <div> 

    </div> 

   </form> 

</body> 

</html>

 

goto design part

 

name                                    

 

loantype     (dropdownlist control)     label3(to display rate of intrest)

 

dropdownlist control properties 

autopostback-true

using system.data.oledb;(name space)

 

using System; 

using System.Collections.Generic; 

using System.Linq; 

using System.Web; 

using System.Web.UI; 

using System.Web.UI.WebControls; 

using System.Data.OleDb;

 

public partial class _Default : System.Web.UI.Page 

{ 

    protected void Page_Load(object sender, EventArgs e) 

    { 

        if (Page.IsPostBack == false) 

        { 

            OleDbConnection con = new OleDbConnection("provider=msdaora.1;user id=scott;password=tiger;data source=server");

            // data source is required if oracle is present in remote system

 

            OleDbCommand cmd = new OleDbCommand("select * from loan", con); 

            OleDbDataReader dr; 

            string loantype1 = "", roi1 = ""; 

            con.Open();

 

            dr = cmd.ExecuteReader(); 

            while (dr.Read()) 

            { 

                // reads cols data 

                loantype1 = dr["loantype"].ToString(); 

                roi1 = dr["roi"].ToString(); 

                // creating listitem 

                ListItem l = new ListItem(loantype1, roi1); 

                // add listitem into dropdownlist 

                DropDownList1.Items.Add(l); 

            } //closing while 

            dr.Close(); 

            con.Close(); 

        } // closing if

    }

 

    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) 

    { 

        Label3.Text = DropDownList1.SelectedValue + "%"; 

    } 

}

 

Goto contrl F5