Tuesday 11 October 2011

ORACLE DATA BASE CONNECTION WITH C#

You need to know that how to connect oracle DB with C#...??
you just Copy & Paste the following code..

c# coding :

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Oracle.DataAccess.Client;

namespace DB_connection
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}


#region DB connection

public void Form1_Load(object sender, EventArgs e)
{

// db connection
     string oradb = "Data Source=localhost;User ID=system;Password=tiger"; //use ur username Nd password

 
// creating connection string object for the connection string class

OracleConnection con = new OracleConnection(oradb);
 
//open the actual connection with db

con.Open();


  //The Command object is used to specify the SQL command text that is executed, either a SQL string or a  //stored procedure

string sql = "select * from employee where empname='karthik' "; //here use ur tables
OracleCommand cmd = new OracleCommand(sql, con);
cmd.CommandType = CommandType.Text;




OracleDataReader dr = cmd.ExecuteReader();
dr.Read();

  label1.Text = dr.GetString(1);
//here label used for simply display the single retriving value from the data base (DB Connection Checking)
 
}



#endregion

}
}

1 comment:

  1. Guyz.,
    I have some more easy And Useful DB Connectivity Programs, as yet you have any doubts means you just post it here Or Email me..if i know ,i will clarify your doubts

    ReplyDelete