using a SqlConnection in C++ / .NET

社会主义新天地 提交于 2019-12-11 10:59:34

问题


When I go to the MSDN page for the SqlConnection class, it only shows examples in C# and VB. Why doesn't MSDN show a C++ example?

I am particularly interested in how a C++ example would get around the lack of the using keyword in C++.


回答1:


Hmmm... after reading What is the Managed C++ equivalent to the C# using statement it seems that the equivalent of:

using (SqlConnection connection = new SqlConnection(connectionString))
{
    // SqlCommand and so...
}

is actually:

{
  SqlConnection conn(connectionString);

  // SqlCommand and so...
}

That is quite impressive, since C++ does not "lack" theusing statement as much as it removes the need for it entirely! I don't think that C#/VB programmers sufficiently appreciate that advantage of C++ (I certainly didn't :) .



来源:https://stackoverflow.com/questions/8036453/using-a-sqlconnection-in-c-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!