B
Bob Grommes
Folks,
I Google in vain for the answer to a seemingly simple question. I am
thwarted by vague documentation.
Why would one do this:
// conn is an already-initialized SqlConnection
SqlCommand cmd = conn.CreateCommand()
as opposed to:
SqlCommand cmd = new SqlCommand();
.... especially when you can pass a string to SqlCommand's ctor and create
the command string in one go if you wish, and CreateCommand() has no such
override?
MSFT docs on CreateCommand describe what it does (evidently just news up an
Sq1Command) but not why a method has been dedicated to this purpose. The
only reason I can think of for its existence is that if you're trying to
write a generic interface to arbitrary back ends, you can use this to create
an command object that's appropriate for the data library you're using. Is
that all it amounts to? Or are the docs failing to mention some other
benefit?
--Bob
I Google in vain for the answer to a seemingly simple question. I am
thwarted by vague documentation.
Why would one do this:
// conn is an already-initialized SqlConnection
SqlCommand cmd = conn.CreateCommand()
as opposed to:
SqlCommand cmd = new SqlCommand();
.... especially when you can pass a string to SqlCommand's ctor and create
the command string in one go if you wish, and CreateCommand() has no such
override?
MSFT docs on CreateCommand describe what it does (evidently just news up an
Sq1Command) but not why a method has been dedicated to this purpose. The
only reason I can think of for its existence is that if you're trying to
write a generic interface to arbitrary back ends, you can use this to create
an command object that's appropriate for the data library you're using. Is
that all it amounts to? Or are the docs failing to mention some other
benefit?
--Bob