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

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
Who is Participating?
Rose BabuSenior Team ManagerCommented:

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..
You could use a LinkServer (in the SQL Manager), however you gonna have a problem in the x64 systems...
AnandSahooAuthor Commented:
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 ?
AnandSahooAuthor Commented:
Thanks I got the solution.
Will ask about more in ASP .net in future
AnandSahooAuthor Commented:
That was helpful
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.