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

前端 未结 4 1544
灰色年华
灰色年华 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:41

    Functionally they are exactly the same.

    However, SqlConnection.CreateCommand() lets you be more agnostic about what type of DB you are using. For example instead of passing a SqlConnection instance around you could pass it around as a DbConnection which would yield a DbCommand.

提交回复
热议问题