How to Display data in Gridview RRS feed

  • Question

  • User134074001 posted

    Hi Friends,

    I have a Gridview and I want to display data in the Gridview, BUT by using a ORACLE DATABASE. I have already connected the database to Visual studio 2013.

    I am using ORACLE Xpress Edition 10g. Now

    when I use this code

    public partial class Gridview : System.Web.UI.Page
    string cnstr = ConfigurationManager.ConnectionStrings["oradb"].ConnectionString.ToString();
    OracleCommand cmd;
    OracleDataAdapter oda;
    DataSet ds = new DataSet();
    OracleConnection cn;
    protected void Page_Load(object sender, EventArgs e)
    cn = new OracleConnection(cnstr);
    cmd = new OracleCommand("select * from EMPLOYEES", cn);
    oda = new OracleDataAdapter(cmd);
    GridView1.DataSource = ds;


    <compilation debug="true" targetFramework="4.5">
    <add assembly="System.Data.OracleClient, Version=, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
    <httpRuntime targetFramework="4.5"/>
    <add name="oradb" connectionString="Data Source=SHAMMATZZ;User ID=hr;Password=scott;Unicode=True" providerName="System.Data.OracleClient"/>

    <!--<add name="oradb" connectionString="Data Source=(DESCRIPTION=
    User Id=hr ;Password=scott" providerName="System.Data.OracleClient"/>-->

    GIVES ME THIS ERROR:-   ORA-12154: TNS:could not resolve the connect identifier specified 

    It would be nice if you could help me.



    Monday, May 8, 2017 4:45 PM

All replies

  • User269602965 posted

    System.Data.OracleClient was deprecated a long time ago.

    Download and install the Oracle ODP.NET driver and client.


    You have three options

    Unmanaged driver 32-bit Classic ODAC Oracle Data Access Client

    Unmanaged driver 64-bit Classic ODAC Oracle Data Access Client

    new Managed driver 32-64-bit with client built into the driver, just add the Oracle TNSNAMES.ORA file to you application /BIN folder and the driver with local reference to /BIN folder and connect.

    Of course some reading is required to set this up correctly.



    The managed driver works in ASP.NET, WPF, and console applications, I use it often.  The exception is being new they still are not fully FIPS-140 compliant if you have that enabled in your environment and EF6 support may still be buggy if you hawk the forums for problems..  But for every day connection, select, update, insert, delete, show stuff in GRIDS, it works well.

    The unmanaged driver is legacy, and relies more on VERSION and BITNESS compatibility, GAC installation of policies, and installation of the Oracle client in addition to the drivers.  It also works very well and having been around many years, less buggy for advanced features.

    ' Get Oracle dataset into .NET dataset for use in DataGrid
    Imports System.Xml.Linq.XElement
    	Dim connectionString As String = ConfigurationManager.ConnectionStrings("AuthenticatedOracleConnectionString").ConnectionString
    	Dim SQL = _
    	Using conn As New OracleConnection(connectionString)
    		Using cmd As New OracleCommand(SQL.Value, conn)
    			Using oda As New OracleDataAdapter(cmd)
    				Dim ds As New DataSet()
    				Me.RadGrid1.DataSource = ds
    				Me.RadGrid1.MasterTableView.DataSource = ds
    			End Using
    		End Using
    	End Using
    Catch ex As Exception
    	AppCalls.WriteToEventLog(ex, "Selecting VW_COUNT_CONTRACTS", "ContractAdjust.aspx.vb")
    End Try

    Tuesday, May 9, 2017 1:02 AM