Jimenemex
Jimenemex

Reputation: 3166

Adding Parameters to Command Vs Adapter

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?

Upvotes: 0

Views: 509

Answers (1)

Zohar Peled
Zohar Peled

Reputation: 82474

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.

Upvotes: 1

Related Questions