1

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++.

JoelFan
  • 37,465
  • 35
  • 132
  • 205

1 Answers1

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 :) .

Community
  • 1
  • 1
JoelFan
  • 37,465
  • 35
  • 132
  • 205