ORACLE DATA BASE CONNECTION WITH C#


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


 }
 }

No comments:

Post a Comment

Pages