SqlCommand

  • Thread starter Thread starter Tony Johansson
  • Start date Start date
T

Tony Johansson

Hello!

I just wonder if example with prefix 1 below is the same as example with
prefix 2 below ?
I assume Exemple with prefix 1 is doing the same this as example with prefix
2 by just using a single row.

1.SqlCommand thisCommand = thisConnection.CreateCommand();


2.SqlCommand thisCommand = new SqlCommand()
2.thisCommand.Connection = thisConnection

//Tony
 
Hello!

I just wonder if example with prefix 1 below is the same as example with
prefix 2 below ?
I assume Exemple with prefix 1 is doing the same this as example with prefix
2 by just using a single row.

1.SqlCommand thisCommand = thisConnection.CreateCommand();

2.SqlCommand thisCommand = new SqlCommand()
2.thisCommand.Connection = thisConnection

The only difference, as far as I am aware, is that the command created
in #1 can ONLY be used with the connection that created it. The
command created in #2 can be associated with any connection you have
available and can move from one connection to another.
 
Hello!

I just wonder if example with prefix 1 below is the same as example with
prefix 2 below ?
I assume Exemple with prefix 1 is doing the same this as example with prefix
2 by just using a single row.

1.SqlCommand thisCommand = thisConnection.CreateCommand();

2.SqlCommand thisCommand = new SqlCommand()
2.thisCommand.Connection = thisConnection

//Tony

Yes, they are the same
 
The only difference, as far as I am aware, is that the command created
in #1 can  ONLY be used with the connection that created it. The
command created in #2 can be associated with any connection you have
available and can move from one connection to another.

Hi,

Not really, all you have to do is modify the Connection property of
the command and then you have a "free" command.
 
The only difference, as far as I am aware, is that the command created
in #1 can  ONLY be used with the connection that created it. The
command created in #2 can be associated with any connection you have
available and can move from one connection to another.

Hmm, after thinking about this, I could be wrong, I sure have been
before!! Since a SqlCommand object does have a Connection property,
you may be able to redirect that after creating using #1. At the very
least, however, the command created with #1 will have that property
already set upon creation, and the command created with #2 would
require that property to be set before it can be used.
 
Back
Top