title: writing sql query in c++ console application?
body: <p>I have been trying to write sql query through my c++ code but Im unable to do this. I have connected the server successfully but dont know the exact way of writing queries to the specific db. My source code is as:</p>
  
  <pre><code>#include &lt;windows.h&gt;
  #include &lt;stdio.h&gt;  // for printf
  #include &lt;sqlext.h&gt;// main SQLAPI++ header
  #include &lt;iostream&gt;
  #include &lt;conio.h&gt;
  #include &lt;string.h&gt;
  #include &lt;sqltypes.h&gt;
  #include&lt;ATLComTime.h&gt;
  
  using namespace std;
  void main(int argc, char* argv[])
  {
      SQLHANDLE henv;
      SQLRETURN rc;
      SQLHANDLE hconn;
      SQLSMALLINT bufsize=0;
      SQLINTEGER nativeerror=0;
      SQLSMALLINT textlen=0;
      unsigned char connStrOut[256];
      SQLWCHAR sqlstate[32];
      SQLWCHAR message[256];
  
      rc = SQLAllocEnv(&amp;henv);
      if (rc != SQL_SUCCESS)
      {
          printf("\nSQLAllocEnv call failed.");
          return;
      }
  
      rc = SQLAllocHandle(SQL_HANDLE_DBC, henv, &amp;hconn);
      if (rc != SQL_SUCCESS)
      {
          SQLFreeHandle(SQL_HANDLE_ENV, henv);
          printf("\nSQLAllocHandle call failed.");
          return;
      }
  
      rc = SQLDriverConnect(hconn, NULL, (SQLWCHAR*)TEXT("DRIVER=SQL Server;SERVER=M1-010;DATABASE=GlobalVideoProcessing;UID=AXACT\\muhammad.ahsan;PWD=Axact123;Trusted_Connection=yes;"), SQL_NTS, NULL, 256, &amp;bufsize, SQL_DRIVER_NOPROMPT);
      if (bufsize!=0)
      {
          printf("Connected successfully.\n");
          SQLDisconnect(hconn);
      }
      else
      {
          rc = SQLGetDiagRec(SQL_HANDLE_DBC, hconn, 1, sqlstate, &amp;nativeerror, message, 256, &amp;textlen);
  
          printf("SQLDriverConnect failed.\n");
          if (rc!=SQL_ERROR)
              printf("%s=%s\n", (CHAR *)sqlstate, (CHAR *)message);
      }
  
      SQLFreeHandle(SQL_HANDLE_DBC, hconn);
      SQLFreeHandle(SQL_HANDLE_ENV, henv);
      getch();
  }
  </code></pre>
  
  <p>I need some guidance . Hopes for suggestion</p>