Solved

DB Access

Posted on 2015-01-18
7
64 Views
Last Modified: 2015-01-18
I'm working on a .net/C# web application. I do not use entity framework. I use ODP.Net to connect to the Oracle db.

I used SQL Server before. For query statement, and it has different calls for queries like select, update or single value select. How about Oracle?  If I assign SQL statement to command insteaf of store procedure, what would be the code ?

 Thanks.
0
Comment
Question by:minglelinch
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 40556534
It's more or less the same exact code; you just change the command type.

e.g.

using (OracleConnection connection = new OracleConnection("connection string"))
{
    using (OracleCommand cmd = new OracleCommand("SELECT * FROM DUAL", connection))
    {
        cmd.CommandType = CommandType.Text;
        connection.Open();
        OracleDataReader reader = cmd.ExecuteReader();

        if (reader.Read())
        {
            // do something with data
        }
    }
}

Open in new window

0
 
LVL 1

Author Comment

by:minglelinch
ID: 40556541
How about update like this?

update emp
set empName = 'namestrong'
where empid = 1

This is a little different.
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 40556551
That's an ExecuteNonQuery call instead of an ExecuteReader call.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:minglelinch
ID: 40556565
So it is exactly like dealing with SQL Server DB ... ?
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 40556575
Yep. All of the data access libraries that I've seen for connecting with various DBMS (and others) follow that same pattern--as far as .NET. Libraries typically implement the classes and interfaces found under the System.Data namespace, so you have some guarantee of what methods you have available to you.
0
 
LVL 1

Author Closing Comment

by:minglelinch
ID: 40556579
Thank you.
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 40556584
The only thing I'll add is that where you'll run into differences are when you use things that are specific to that DBMS. Things like user-defined types and arrays get handled slightly differently with the Oracle stuff.
0

Featured Post

Major Incident Management Communications

Major incidents and IT service outages cost companies millions. Often the solution to minimizing damage is automated communication. Find out more in our Major Incident Management Communications infographic.

Question has a verified solution.

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

Suggested Solutions

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

739 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