Opening a CRecordset derived class problem
-
I am currently working on a system that uses an Access database to store a list of url's waiting to be processed. I need to be able to add to, and amend the database, and so, I have derived a class from the CRecordset class called CURLRecordset using the classwizard. In my application, I can succesfully open a CDatabase object in order to connect to the database, but when it comes to opening the actual recordsets associated with it: /* CURLRecordset* unparsed_urls; CDatabase* db; CString sql; */ unparsed_urls = new ( CUnparsed ) ( db ); sql.Format ( "SELECT * FROM urls WHERE status = %d;", STATUS_NOT_CRAWLED ); unparsed_urls->Open ( CRecordset::snapshot, (LPCTSTR)sql ); I get the following exception: "Invalid character value for cast specification on column number 2 (urladdress)" I have traced the source of the exception to the final move() function call in the CRecordset class's Open() method, but I have no idea how to deal with it. My database schema is as follows: TABLE urls = ( long urlid (PRIMARY KEY) VARCHAR(256) urladdress long status long level long keywordid long sourceid ) The header file for the CURLRecordset class is as follows: class CURLRecordset : public CRecordset { public: CURLRecordset(CDatabase* pDatabase = NULL); DECLARE_DYNAMIC(CURLRecordset) // Field/Param Data //{{AFX_FIELD(CURLRecordset, CRecordset) long m_keywordid; long m_level; long m_sourceid; long m_status; CString m_urladdress; long m_urlid; //}}AFX_FIELD // Overrides // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CURLRecordset) public: virtual CString GetDefaultConnect(); // Default connection string virtual CString GetDefaultSQL(); // Default SQL for Recordset virtual void DoFieldExchange(CFieldExchange* pFX); // RFX support //}}AFX_VIRTUAL // Implementation #ifdef _DEBUG virtual void AssertValid() const; virtual void Dump(CDumpContext& dc) const; #endif }; Any help will be greatly appreciated!
-
I am currently working on a system that uses an Access database to store a list of url's waiting to be processed. I need to be able to add to, and amend the database, and so, I have derived a class from the CRecordset class called CURLRecordset using the classwizard. In my application, I can succesfully open a CDatabase object in order to connect to the database, but when it comes to opening the actual recordsets associated with it: /* CURLRecordset* unparsed_urls; CDatabase* db; CString sql; */ unparsed_urls = new ( CUnparsed ) ( db ); sql.Format ( "SELECT * FROM urls WHERE status = %d;", STATUS_NOT_CRAWLED ); unparsed_urls->Open ( CRecordset::snapshot, (LPCTSTR)sql ); I get the following exception: "Invalid character value for cast specification on column number 2 (urladdress)" I have traced the source of the exception to the final move() function call in the CRecordset class's Open() method, but I have no idea how to deal with it. My database schema is as follows: TABLE urls = ( long urlid (PRIMARY KEY) VARCHAR(256) urladdress long status long level long keywordid long sourceid ) The header file for the CURLRecordset class is as follows: class CURLRecordset : public CRecordset { public: CURLRecordset(CDatabase* pDatabase = NULL); DECLARE_DYNAMIC(CURLRecordset) // Field/Param Data //{{AFX_FIELD(CURLRecordset, CRecordset) long m_keywordid; long m_level; long m_sourceid; long m_status; CString m_urladdress; long m_urlid; //}}AFX_FIELD // Overrides // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CURLRecordset) public: virtual CString GetDefaultConnect(); // Default connection string virtual CString GetDefaultSQL(); // Default SQL for Recordset virtual void DoFieldExchange(CFieldExchange* pFX); // RFX support //}}AFX_VIRTUAL // Implementation #ifdef _DEBUG virtual void AssertValid() const; virtual void Dump(CDumpContext& dc) const; #endif }; Any help will be greatly appreciated!
I think the problem may be in your DoFieldExchange() function...I can't think of anywhere else that the problem could be.