Thursday, September 5, 2013

C# Querying From An Oracle Database














In this blog we will go over how to query an Oracle database in ASP.NET using the System.Data.OracleClient data provider in C#.

Namespaces:

using System.Web.Configuration;
using System.Data.OracleClient;
using System.Data;

            string cs = WebConfigurationManager.ConnectionStrings["SomeConnectionString"].ConnectionString;

using (OracleConnection oc = new OracleConnection(cs))
{
oc.Open();
DataTable dt = new DataTable();
OracleCommand ocmd = new OracleCommand("SELECT * FROM SOMETABLE", oc);
OracleDataAdapter oda = new OracleDataAdapter(ocmd);

oda.Fill(dt);

GridView1.DataSource = dt;
GridView1.DataBind();

}

No comments:

Post a Comment