在.Net中,创建新的SqlCommand
对象并将其附加到SqlConnection
并在现有的SqlConnection
对象上调用CreateCommand()
有什么功能差异?SqlConnection.CreateCommand和新的SqlCommand是否有区别?
21
A
回答
31
不,他们是一样的东西。
我拆开SqlConnection.CreateCommand
,发现这个:
public SqlCommand CreateCommand()
{
return new SqlCommand(null, this);
}
这证明他们真的是同样的事情。
7
在功能上它们是完全一样的。
但是,SqlConnection.CreateCommand()
可让您更加了解您正在使用的数据库类型。例如,您可以将作为DbConnection
传递给SqlConnection
,这样可以产生DbCommand
。
9
他们做同样的事情。 SqlConnection.CreateCommand
背后的基本原理是实施工厂模式。
相关问题
- 1. $ @和$ $是否有区别?
- 2. //和m //是否有区别?
- 3. Ruby中的“!=”和“!〜”是否有区别?
- 4. 1.week和1.weeks是否有区别?
- 5. 在Perl中,/^/和/ ^/m是否有区别?
- 6. QString&和QString之间是否有区别?
- 7. .JPG和.jpg是否有区别?
- 8. ** copy **和** addAll **之间是否有区别?
- 9. $(e.currentTarget)和$(this)之间是否有区别?
- 10. UTF8Encoding.UTF8.GetBytes和Encoding.UTF8.GetBytes是否有区别?
- 11. `ListView.invalidateViews()`和'Adapter.notifyDataSetChanged()'之间是否有区别?
- 12. “margin:0 auto”是否有区别?和“margin:auto;”
- 13. CGImageGetWidth(workingImage.CGImage)和workingImage.size.width是否有区别?
- 14. `* x`和`x *`是否有区别?
- 15. TINYINT(1)和INT(1)是否有区别?
- 16. Interop.AZROLESLib和Microsoft.Interop.Security.AzRoles是否有区别?
- 17. Web API和MVC HttpConfiguration是否有区别?
- 18. DB_DOUBLE和dbDouble是否有区别?
- 19. if $ str =“”和if($ str)是否有区别?
- 20. '/'和''路线是否有区别?
- 21. Phongap config.xml和Cordova config.xml是否有区别?
- 22. WebRTC和Websockets。是否有区别
- 23. HttpContext.Current.Request和HttpContext.Request是否有区别?
- 24. RSpec中'expect'和'should'是否有区别?
- 25. MASM shellcode和NASM shellcode是否有区别
- 26. _function和function之间是否有区别?
- 27. variant()和variant之间是否有区别?
- 28. RenderPartial和RenderPage是否有区别?
- 29. replica和replica之间是否有区别
- 30. ui:fragment和s:fragment之间是否有区别?