Query Database using OracleConnection - CSharp Database

CSharp examples for Database:Oracle

Description

Query Database using OracleConnection

Demo Code


using System.Windows.Forms;
using System.Data.OracleClient;
using System.Data;
using System.Threading.Tasks;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System;/*  w w w .  j a v a  2 s . c  o  m*/

public class Main{
        public static DataSet QueryDatabase(string query)
        {

            string oracleDB = connect();
            try
            {
                OracleConnection conn = new OracleConnection(oracleDB);
                string strSQL = query;
                OracleCommand cmd = new OracleCommand(strSQL, conn);//asdfasdsdafsd
                cmd.CommandType = CommandType.Text;
                OracleDataAdapter da = new OracleDataAdapter(cmd);
                DataSet ds = new DataSet();
                da.Fill(ds, "ss");
                conn.Close();
                //MessageBox.Show("database working");
                return ds;
            }
            catch (OracleException ex)
            {
                MessageBox.Show("No records found");
                MessageBox.Show(ex.Message);
            }
            return null;
        }
        public static string connect()
        {
            return "Data Source=xe;User Id=t00126681;Password=hello;";
            //return "Data Source=localhost:1521/orcl;User Id=C##Nazmul;Password=nada;";

        }
}

Related Tutorials