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

parameterized queries

Is it ok to set the parameters of an SqlCommand before they appear in the command text?  ie,

myCommand.Parameters.add("@value", myInt);
myCommand.CommandText = "SELECT * FROM table WHERE val=@value";
somereader = myComand.ExecuteReader();

It's a long story why I'm asking....would this throw an exception?
0
ARACK04
Asked:
ARACK04
  • 2
1 Solution
 
TertioptusCommented:
Yes it is ok
0
 
TertioptusCommented:
Yes, because the actual command text is not considered until it is executed.  (i.e. myComand.ExecuteReader();
)

so it doesn't matter what order, as long as they are both before any processing
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

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