[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2011-05-09
5
Medium Priority
?
424 Views
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
0
Comment
Question by:AnandSahoo
  • 3
5 Comments
 
LVL 16

Accepted Solution

by:
Rose Babu earned 1000 total points
ID: 35726472
Hi,

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

http://www.connectionstrings.com/oracle#p12


Sample code to get data from oracle db

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

Open in new window

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

Happy Programming..
0
 

Expert Comment

by:Aquinos
ID: 35727096
You could use a LinkServer (in the SQL Manager), however you gonna have a problem in the x64 systems...
0
 

Author Comment

by:AnandSahoo
ID: 35735150
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 ?
0
 

Author Comment

by:AnandSahoo
ID: 35866080
Thanks I got the solution.
Will ask about more in ASP .net in future
0
 

Author Closing Comment

by:AnandSahoo
ID: 35866083
That was helpful
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

829 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