Can't create new record using CRecordset derived class 
Author Message
 Can't create new record using CRecordset derived class

Hi, I'm attempting to add a record to an SQL database using a CRecordset
object. at the "my code" level, i'm doing the following:

long User::Create()
{
        UserSet         rsTemp;         // UserSet is derived from CRecordset
        m_dwStat = RECCOM_UNEXPECTED;
        try
        {
                rsTemp.Open( CRecordset::snapshot,
                        NULL,
                        CRecordset::appendOnly |
                        CRecordset::executeDirect );
                if( rsTemp.CanAppend() == TRUE )
                {
                        rsTemp.AddNew();                                // prepare new record
                        rsTemp = m_rsUser;                              // copy field values from member buffer
                        rsTemp.Update();                                // call update <<< FAILS IN HERE
                        m_dwStat = Load( rsTemp.m_SID );
                }
        }
        catch( etc... )

Quote:
}

My code fails during the execution of the Update call, after following it
through the de{*filter*} I have verified that the rsTemp CRecordset has all the
appropriate values in its fields and they are all marked dirty - but the
m_strUpdateSQL statement that gets constructed has question marks in all
the places where a field value should be when it finally executes the
ExecuteUpdateSQL method below.

nRetCode is returned as -1 and an exception is thrown.

void CRecordset::ExecuteUpdateSQL()
{
        RETCODE nRetCode;

        if(!(m_dwOptions & optimizeBulkAdd))
        {
                USES_CONVERSION;
                AFX_ODBC_CALL(::SQLExecDirect(m_hstmtUpdate,
                        (UCHAR*)T2A((LPTSTR)(LPCTSTR)m_strUpdateSQL), SQL_NTS));
                if (!Check(nRetCode))
                        ThrowDBException(nRetCode, m_hstmtUpdate);
        }
        etc...

Quote:
}

 m_strUpdateSQL =
 "INSERT INTO "dbo"."users"
("SID","name","first_name","middle_name","name_suffix","friendly_name","alia
s_name","approved","last_ISP_used","last_comp_used","last_OS_used") VALUES
(?,?,?,?,?,?,?,?,?,?,?)"}


Mon, 20 Sep 1999 03:00:00 GMT  
 Can't create new record using CRecordset derived class

Duh...  Boy do I feel dumb.  Turns out that the very 1st field in the SQL
INSERT was defined a 'numeric' in the database, and i was passing
non-numeric characters; hence all the question marks because it never got
past the 1st parameter substitution.

-bl-



Tue, 21 Sep 1999 03:00:00 GMT  
 Can't create new record using CRecordset derived class


Fri, 19 Jun 1992 00:00:00 GMT  
 Can't create new record using CRecordset derived class

Hi
thanks for the suggestion, unfortunately it had no effect.



Tue, 21 Sep 1999 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Problem in adding new records using CRecordset class (in dialogbox)

2. New Class derived from Class which derived from CWindowImpl

3. My CRecordset derived class doesn't work in Release mode

4. Can't derive class from CRecordSet

5. Can't derive class from CRecordSet

6. Slow Record Addition using VC++ CRecordSet's AddNew and Update functions

7. Problem using MFC Extension DLL and CRecordset-derived class

8. How to Create CCtrlView derived class based on CTreeCtrl derived class

9. Slow Record Addition using CRecordSet's AddNew and Update functions

10. How to Create CCtrlView derived class based on CTreeCtrl derived class

11. Create a new Dialog derived from own Class

12. How to derive new ATL COM class from ADO's _Recordset

 

 
Powered by phpBB® Forum Software