ODBC SQL

hi,

 How can I insert data into my ODBC database ?
 I'm using:

 LPCSTR szSQL="INSERT INTO PRINCIPAL (v1,v2,v3,v4,v5,v6,v7,v8,v9,va) VALUES ('a','b','c','d','e','f','g','h','i','j')";
SQLPutData(hstmt,(unsigned char*)szSQL, SQL_NTS);
SQLExecute(hstmt);

 Don't work!
LVL 1
RogerioSilvaAsked:
Who is Participating?
 
cybsashaConnect With a Mentor Commented:
////////Connect to ODBC
SQLRETURN sr;
    char szDSN[] = "LocalDb30";
    char szUID[] = "sa";
    char szAuthStr[] = "";
    // Allocate Environment
    sr = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &hOdbcEnv);
    if(sr != SQL_SUCCESS)
        TRACE("Error in Allocating Environment.\n");
    // Set the App's ODBC Version
    sr = SQLSetEnvAttr(hOdbcEnv, SQL_ATTR_ODBC_VERSION,
            (SQLPOINTER)SQL_OV_ODBC3, SQL_IS_INTEGER);
    if(sr != SQL_SUCCESS)
        TRACE("Error in Setting ODBC Version.\n");
    // Allocate Connection
    sr = SQLAllocHandle(SQL_HANDLE_DBC, hOdbcEnv, &hDbConn);
    if(sr != SQL_SUCCESS)
        TRACE("Error in Allocating Connection.\n");
    sr = SQLSetConnectAttr(hDbConn, SQL_ATTR_ACCESS_MODE,
        (void*)SQL_MODE_READ_WRITE , SQL_IS_UINTEGER);
    if(sr != SQL_SUCCESS)
        TRACE("Error in SetConnectAttr.\n");
/*    // Set Connect Timeout
    sr = SQLSetConnectAttr(hDbConn, SQL_ATTR_LOGIN_TIMEOUT, (void*)5, 0);
    if(sr != SQL_SUCCESS)
        TRACE("Error in Setting Login Timeout.\n");
*/
    // Connect to Data Source
    sr = SQLConnect(hDbConn, (UCHAR *)szDSN, SQL_NTS,
                        (UCHAR *)szUID, SQL_NTS,
                        (UCHAR *) szAuthStr, SQL_NTS);
     // Get Error Info or warnings for SQL_SUCCESS_WITH_INFO
      if(sr != SQL_SUCCESS)
    {
        SQLCHAR SqlState[6];
        SQLINTEGER NativeError;
        SQLCHAR ErrMsg[SQL_MAX_MESSAGE_LENGTH];
        int i = 1;
        TRACE("Error in SQLConnect(): %d.\n", sr);
        while(SQLGetDiagRec(SQL_HANDLE_DBC, hDbConn, i, SqlState,
                            &NativeError, ErrMsg, sizeof(ErrMsg), NULL)
                            != SQL_NO_DATA)
            TRACE("Diag: %d, SQLSTATE: %s NativeError: %d ErrMsg: %s\n",
                i++, SqlState, NativeError, ErrMsg);
    }
    else
        TRACE("Connected OK\n");
    SQLINTEGER tmp;
    sr = SQLGetDiagField(SQL_HANDLE_DBC, hDbConn, 0, SQL_DIAG_NUMBER,
        &tmp, sizeof(tmp), NULL);
      if(sr != SQL_SUCCESS)
    {
        SQLCHAR SqlState[6];
        SQLINTEGER NativeError;
        SQLCHAR ErrMsg[SQL_MAX_MESSAGE_LENGTH];
        int i = 1;
        TRACE("Error in SQLConnect(): %d.\n", sr);
        while(SQLGetDiagRec(SQL_HANDLE_DBC, hDbConn, i, SqlState,
                            &NativeError, ErrMsg, sizeof(ErrMsg), NULL)
                            != SQL_NO_DATA)
            TRACE("Diag: %d, SQLSTATE: %s NativeError: %d ErrMsg: %s\n",
                i++, SqlState, NativeError, ErrMsg);
    }
    else
        TRACE("Got Diag OK\n");
   
////////////Insert into PRINCIPAL
     SQLRETURN sr;
    SQLHSTMT hstmt;
      SQLCHAR mySql[] ="INSERT INTO PRINCIPAL (v1,v2,v3,v4,v5,v6,v7,v8,v9,va) VALUES ('a','b','c','d','e','f','g','h','i','j')";
  sr = SQLAllocHandle(SQL_HANDLE_STMT, hDbConn, &hstmt);    
  sr = SQLExecDirect(hstmt, (UCHAR*)mySql, SQL_NTS);

0
 
thinooCommented:
SQLPrepare(m_hstmt,(UCHAR*)SQLString),SQL_NTS);
SQLBindParameter(m_hstmt,...,)
<load data>
SQLExecute(m_hstmt);

would work.

Thanks,
0
 
RogerioSilvaAuthor Commented:
I tried:

LPCSTR szSQL="INSERT INTO PRINCIPAL (v1,v2,v3,v4,v5,v6,v7,v8,v9,va) VALUES ('a','b','c','d','e','f','g','h','i','j')";
SQLPrepare(hstmt,(unsigned char*)szSQL, SQL_NTS);
SQLBindParameter(hstmt,1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, 50, 0, "HERE", 0, &v2);
SQLExecute(hstmt);

But, Don't work.
0
[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

 
cybsashaCommented:
This does't work , i'll send you source code, maybe you don't open ODBC corectly
0
 
cybsashaCommented:
Mistake , if this doesn't work(I mean):-)
0
 
RogerioSilvaAuthor Commented:
Thank You!
0
All Courses

From novice to tech pro — start learning today.