Click here to Skip to main content
14,574,905 members

C / C++ / MFC

 
GeneralRe: C++ Pin
Richard MacCutchan19-May-20 5:01
mveRichard MacCutchan19-May-20 5:01 
GeneralRe: C++ Pin
Member 1461181419-May-20 5:36
MemberMember 1461181419-May-20 5:36 
GeneralRe: C++ Pin
Richard MacCutchan19-May-20 6:12
mveRichard MacCutchan19-May-20 6:12 
GeneralRe: C++ Pin
markkuk19-May-20 19:24
Membermarkkuk19-May-20 19:24 
QuestionOld guy question - VS2008 Professional and it's help system - why is it so f'd up? Pin
charlieg18-May-20 13:05
Membercharlieg18-May-20 13:05 
AnswerRe: Old guy question - VS2008 Professional and it's help system - why is it so f'd up? Pin
Victor Nijegorodov18-May-20 21:05
MemberVictor Nijegorodov18-May-20 21:05 
GeneralRe: Old guy question - VS2008 Professional and it's help system - why is it so f'd up? Pin
charlieg20-May-20 2:24
Membercharlieg20-May-20 2:24 
QuestionC++ DB : SQLServer : SQLExecute - Insert statement returning Error -2 Pin
SureshBL18-May-20 12:00
MemberSureshBL18-May-20 12:00 
Hi C++ Gurus, 

Below code is generating error code -2. Its working fine for sql queries like "select * from emp", but where as in Insert statement its returning error code.  Please help.

Regards,
Suresh

#include "database.h"

int main(){

SQLRETURN ret = 0; /* ODBC API return status */

SQLHENV env;
SQLHDBC dbc;
SQLHSTMT stmt;

SQLSMALLINT msg_len = 0;
SQLCHAR sql_state[6], message[256];
SQLINTEGER native_error = 0;

try{
    ret = SQLAllocEnv(&env);
    ret = SQLAllocConnect(env, &dbc);
    ret = SQLConnect(dbc, (SQLCHAR*)"KarTarDB", strlen("KarTarDB"), (SQLCHAR*)"sa",2,(SQLCHAR*)"KarTarPwd",9);

    if(ret == SQL_INVALID_HANDLE || ret < 0) {
        cout << "Connection open failure." << endl;
        ret = SQLGetDiagRec(SQL_HANDLE_STMT, stmt, 1, sql_state, &native_error, message, sizeof(message), &msg_len);
        cout << ret << endl;
    } else{
        char sql[100]="INSERT INTO emp(name, age, dob) VALUES ('john', 23, '010101')";

        ret = SQLPrepare(stmt,(unsigned char*)sql, SQL_NTS);//strlen(sql));
        ret = SQLExecute(stmt);//,(SQLCHAR*)sql,strlen(sql));

        if(ret == SQL_ERROR || ret < 0) {
            cout << "ResultSet Error: " << ret << endl;
            //ret = SQLGetDiagRec(SQL_HANDLE_STMT, stmt, 1, sql_state, &native_error, message, sizeof(message), &msg_len);
        }else{
            cout << "Done" << endl;
        }
    }
}catch(...) {
    cout << "Database error.." << endl;
    }
return 0;
}

AnswerRe: C++ DB : SQLServer : SQLExecute - Insert statement returning Error -2 Pin
Victor Nijegorodov18-May-20 21:01
MemberVictor Nijegorodov18-May-20 21:01 
GeneralRe: C++ DB : SQLServer : SQLExecute - Insert statement returning Error -2 Pin
SureshBL19-May-20 3:02
MemberSureshBL19-May-20 3:02 
GeneralRe: C++ DB : SQLServer : SQLExecute - Insert statement returning Error -2 Pin
Victor Nijegorodov19-May-20 7:36
MemberVictor Nijegorodov19-May-20 7:36 
GeneralRe: C++ DB : SQLServer : SQLExecute - Insert statement returning Error -2 Pin
SureshBL19-May-20 10:59
MemberSureshBL19-May-20 10:59 
GeneralRe: C++ DB : SQLServer : SQLExecute - Insert statement returning Error -2 Pin
jeron119-May-20 11:25
Memberjeron119-May-20 11:25 
GeneralRe: C++ DB : SQLServer : SQLExecute - Insert statement returning Error -2 Pin
SureshBL19-May-20 13:19
MemberSureshBL19-May-20 13:19 
GeneralRe: C++ DB : SQLServer : SQLExecute - Insert statement returning Error -2 Pin
SureshBL19-May-20 13:25
MemberSureshBL19-May-20 13:25 
GeneralRe: C++ DB : SQLServer : SQLExecute - Insert statement returning Error -2 Pin
jeron120-May-20 4:46
Memberjeron120-May-20 4:46 
Questionkernel32.lib Pin
CalinNegru18-May-20 11:10
MemberCalinNegru18-May-20 11:10 
AnswerRe: kernel32.lib Pin
Daniel Pfeffer18-May-20 19:49
professionalDaniel Pfeffer18-May-20 19:49 
GeneralRe: kernel32.lib Pin
CalinNegru19-May-20 0:02
MemberCalinNegru19-May-20 0:02 
QuestionHow is this possible? Pin
Tim ONeil17-May-20 4:47
MemberTim ONeil17-May-20 4:47 
AnswerRe: How is this possible? Pin
Richard MacCutchan17-May-20 5:31
mveRichard MacCutchan17-May-20 5:31 
GeneralRe: How is this possible? Pin
Tim ONeil17-May-20 5:39
MemberTim ONeil17-May-20 5:39 
GeneralRe: How is this possible? Pin
Richard MacCutchan17-May-20 6:28
mveRichard MacCutchan17-May-20 6:28 
GeneralRe: How is this possible? Pin
Richard MacCutchan17-May-20 22:12
mveRichard MacCutchan17-May-20 22:12 
GeneralRe: How is this possible? Pin
Richard MacCutchan19-May-20 23:55
mveRichard MacCutchan19-May-20 23:55 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.