Click here to Skip to main content
15,887,376 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello All,

I am facing a problem with my code.
My Code is written in VC++ and using it i am trying to access a MDB file which has contents of Memo datatytpe. The code works fine if i change the datatype to text [Which i can't] but with memo datatypes its not working & throwing some error.
Note: I am using CRecordset Class
CODE SNIPPET:

C#
/*Get all the language Strings from the Database.. */
strReadSqlAllLangString ="SELECT * FROM StringsTable";
nRetVal = rs_lang_all.Open ( CRecordset::forwardOnly, \
            strReadSqlAllLangString, CRecordset::readOnly );

// Create a CDBVariant object to
// store field data
CDBVariant varValue;

nFields = rs_lang_all.GetODBCFieldCount( );
short nFieldType = DEFAULT_FIELD_TYPE;
while ( !rs_lang_all.IsEOF() )
{
    for(nIndex = 0; nIndex < nFields; nIndex++ )
    {
        /* Get the current field value and put it in strString1 */
        rs_lang_all.GetFieldValue(nIndex, strString1);
        //CString string = varValue.m_pstring;
        arr_strAllLangStrings[nIndex][nLangStr] = strString1;
    }
    /*Move to the next nSet of strings in all 28 languages*/
    rs_lang_all.MoveNext();
    nLangStr++;
}

/**/


strString1 is a reference variable of CString tyoe which stores the field value.

On googling i found that there is something called CDBVariant but i am unable to make use of it.

Please someone identify the mistake in my code and let me know the solution to fix this issue i.e. the memo string data should be fetched properly.

Thanks & Regards
Dinesh
Posted
Comments
Jochen Arndt 4-Jul-13 7:28am    
It would help to know the exact error (not only the error number but all error information). To get the error information, catch CDBExceptions. With debug builds you may get it also from the trace output.

To use CDBVariant, just pass it by reference instead of the CString and optionally pass also the field type. When not passing the field type (using the default type), you should call GetODBCFieldInfo() to know which union member of the CDBVariant is valid.

1 solution

OK below is what you have so far:

C#
/*Get all the language Strings from the Database.. */
strReadSqlAllLangString ="SELECT * FROM StringsTable";
nRetVal = rs_lang_all.Open ( CRecordset::forwardOnly, \
            strReadSqlAllLangString, CRecordset::readOnly );
//I am presuming that you have created and initialized a CString strReadSqlAllLangString, strString1; and a CFile rs_lang_all; someplace above this part of the snippet, and all of it is within the same function set of brackets.  Then there is UINT nRetVal, nFields, nIndex, nLangStr; 


// Create a CDBVariant object to
// store field data
CDBVariant varValue;//this does nothing as you don't use it below.

nFields = rs_lang_all.GetODBCFieldCount( );
short nFieldType = DEFAULT_FIELD_TYPE;  //why is this here as is not used below?
while ( !rs_lang_all.IsEOF() )
{
    for(nIndex = 0; nIndex < nFields; nIndex++ )
    {
        /* Get the current field value and put it in strString1 */
        rs_lang_all.GetFieldValue(nIndex, strString1);
        //CString string = varValue.m_pstring;// varValue.m_pstring = new CString();
        arr_strAllLangStrings[nIndex][nLangStr] = strString1;//where is the arr_strAllLangStrings[nIndex][nLangStr] been created and initialized?
    }
    /*Move to the next nSet of strings in all 28 languages*/
    rs_lang_all.MoveNext();
    nLangStr++;
}

/**/


It is better to show the whole function, you talk of CMemo but don't show any variable of the kind. CDBVariant is a DB file IO function not useful to CString. Memo is a text style variation datatype. Examine the Memo structure if any, and get a better feel for it.
 
Share this answer
 
Comments
[no name] 18-Jul-13 0:44am    
Do u know of any other way to extract the MEMO data from mdb using CRecordset. The ultimate goal is to fetch the MEMO string data from mdb file and store it in a CString array.
If u know any alternative method please share.
Thanks anyways.
PS: This application is for Unicode characters.
The_Inventor 18-Jul-13 1:01am    
What is MEMO data? And did you actually read and try the solution, or are you unable to provide the necessary info so that I may help you better?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900