Is There Any Difference Between SqlConnection.CreateCommand and new SqlCommand?

前端 未结 4 1553
灰色年华
灰色年华 2020-12-08 14:22

In .Net, is there any functional difference between creating a new SqlCommand object and attaching a SqlConnection to it and calling CreateCo

4条回答
  •  佛祖请我去吃肉
    2020-12-08 14:56

    No, they are the same thing.

    I disassembled SqlConnection.CreateCommand and found this:

    public SqlCommand CreateCommand()
    {
            return new SqlCommand(null, this);
    }
    

    which proves that they really are the same thing.

提交回复
热议问题