问题
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