How to connect to a oracle database and run some sample query using ASP.NET

Posted on 2011-05-09
Last Modified: 2012-06-28
Hi Team,

Need your help in the following.

I have a odbc connection configured in my PC for oracle database. (Oracle for orahome92)

using Visual studio web developer 2008 version (Express edition free version),

need to connect to the database using connection string.
then run 2 distinct count queries like

select distinct count empid where dept = finance
select distinct count where sal > 10000and dept = finance

2nd one is subset of first one

Just need one page web screen to show the values returned in the above queries.

then also show the percentage of it on the screen

Have tried many connection string.
Either I am getting error in connection or if its connecting unable to execute the query to return the value and show on the screen.

Request your help
Question by:AnandSahoo
    LVL 16

    Accepted Solution


    for the oracle db connection in .net just follow the below link

    Sample code to get data from oracle db

    OracleCommand myCommand = new OracleCommand("SELECT count(*) as countVal FROM table", myConnection);
      OracleDataReader myReader = myCommand.ExecuteReader(System.Data.CommandBehavior.Default);
        while (myReader.Read())
          //Obtain OracleLob directly from OracleDataReader
          OracleLob myLob = myReader.GetOracleLob(myReader.GetOrdinal("countVal"));
          if (!myLob.IsNull)
            // Do Something

    Open in new window

    i didnt check this code. so you can just try and start with it.

    Happy Programming..

    Expert Comment

    You could use a LinkServer (in the SQL Manager), however you gonna have a problem in the x64 systems...

    Author Comment

    Hi srosebabu,

    This is really helpful. I got something to start with.
    I am able to show the value in a text box.

    Can you also help me with the following ?

    1. If I have multiple queries to run,do I have to take multiple commands and readers ? OR I can close one and use the same name to run another query ?

    2. I want to format the query result count in colors. Lets say if its more than 90 then it should show green,80 to 90 amber and less than 80 red,how can I achieve this. The values are shown in textbox.

    3. Instead of count (*) if I need to take the rows and column values returned, What are the changes I need to do ?

    Author Comment

    Thanks I got the solution.
    Will ask about more in ASP .net in future

    Author Closing Comment

    That was helpful

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
    Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now