• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 75
  • Last Modified:

DB Access

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
minglelinch
Asked:
minglelinch
  • 4
  • 3
1 Solution
 
käµfm³d 👽Commented:
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
 
minglelinchAuthor Commented:
How about update like this?

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

This is a little different.
0
 
käµfm³d 👽Commented:
That's an ExecuteNonQuery call instead of an ExecuteReader call.
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
minglelinchAuthor Commented:
So it is exactly like dealing with SQL Server DB ... ?
0
 
käµfm³d 👽Commented:
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
 
minglelinchAuthor Commented:
Thank you.
0
 
käµfm³d 👽Commented:
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
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.

Join & Write a Comment

Featured Post

Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now