0

I'm curious if there is a difference, if any between adding Parameters to the OracleCommand and then adding them to the OracleDataAdapter or by directly adding them to the OracleDataAdapter?

For example,

Adding them to the OracleCommand and then linking them to the OracleDataAdpater

string f= "foo";
string sql = "SELECT @c FROM Dual";

using(OracleCommand command = new OracleCommand(sql, this.Connection))
{
    OracleParameter param = new OracleParameter("@c", f);
    command.Parameters.Add(param);
    OracleDataAdapter adapter = new OracleDataAdapter(command);
    adapter.SelectCommand = command;
    DataSet dataset = new DataSet();
    adapter.Fill(dataset);
    return dataset;
}

Adding them directly to the OracleDataAdapter

string f= "foo";
string sql = "SELECT @c CalcVarValue FROM Dual";
using(OracleCommand command = new OracleCommand(sql, this.Connection))
{
    OracleDataAdapter adapter = new OracleDataAdapter(command);
    adapter.SelectCommand.Parameters.Add(new OracleParameter("@c", f));
    DataSet dataset = new DataSet();
    adapter.Fill(dataset);
    return dataset;
}

Is one way more preferred over the other? Is adding to the OracleDataAdapter directly faster in execution compared to the other method?

1 Answer 1

1

There is no difference whatsoever. In both cases, the parameter is added to the OracleCommand.

Choosing between these two coding styles is a matter of personal preference, coding conventions you are obligated to (if exists) and mostly, opinion.

Personally, I tend to go with the shortest possible code that you can still read a year from the day you wrote it and understand what it does without having to think about it, or as someone once wrote (I think it was on Meta.SE) - In this industry, you should write your code as simple as possible, because the person that will take over the project after you will most likely be an idiot.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.