Design a Windows application Form like the below screenshot.

# Write code to insert record into Employee table. (provided below)
# To know the connection string for oracle database, go to , Server Explorer->WriteClick on Data Connections ->Add Connection->Then provide the Global Database Name (SID), UserID and password as set at the time of installing Oracle .
Notes : User ID : Scott (Locked, So no changes)
Password: tiger (Locked, No changes)
Server : GDN (here 'GDN' in my Machine)
Only you have to provide the Global Database Name , at the time of installation.
See the below screenshot to create the connection using Server Explorer.



Then you will find the connection string which will be created automatically and set this connection string, with OracleConnection instance.
For details see the code details :
------------------------------------------------------
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.OracleClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace ADOwithOra
{
public partial class Employee : Form
{
OracleConnection oracleConn;
public Employee()
{
InitializeComponent();
oracleConn = new OracleConnection();
oracleConn.ConnectionString = "Data Source=GDN;User ID=scott;Password=tiger;Unicode=True";
oracleConn.Open();
}
private void button1_Click(object sender, EventArgs e)
{
try
{
if (oracleConn.State == ConnectionState.Open)
{
oracleConn.Close();
}
oracleConn.Open();
//OracleCommand cmd = new OracleCommand("insert into Employee(EmpNo,EmpName,Sal) values(5,'Ravi',23000)", oracleConn); --->Hardcoding
OracleCommand cmd = new OracleCommand("insert into Employee values(" + textBox1.Text + ",'" + textBox2.Text + "'," + textBox3.Text + ")", oracleConn);
cmd.ExecuteNonQuery();
MessageBox.Show("Employee information added successfully...", "Employee Details", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception e2)
{
MessageBox.Show(e2.ToString());
}
}
private void btnReset_Click(object sender, EventArgs e)
{
textBox1.Text = "";
textBox2.Text = "";
textBox3.Text = "";
}
}
}
--------------------------------------------------
Result screenshot:

See the Oracle database screenshot:

Now we can do more works using Oracle 9i in ADO.NET.
All the best...
Nice informative........
ReplyDelete