如何从具有Memo数据类型字段的MS Access数据库(mdb文件)获取值 [英] How to get value from MS Access Database (mdb file) with fields of Memo datatype

查看:413
本文介绍了如何从具有Memo数据类型字段的MS Access数据库(mdb文件)获取值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我的代码遇到问题。

我的代码是用VC ++编写的,我用的是尝试访问具有Memo datatytpe内容的MDB文件。如果我将数据类型更改为文本[我不能]但代码数据类型不能正常工作&抛出一些错误。

注意:我正在使用CRecordset Class

CODE SNIPPET:



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:

/*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是CString tyoe的参考变量,用于存储字段值。



谷歌搜索我发现有一些名为CDBVariant但我无法使用它。



请有人在我的代码中识别错误并让我知道修复的解决方案这个问题,即应该正确提取备忘录字符串数据。



谢谢&问候

Dinesh



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

推荐答案

以下是你现在所拥有的:



OK below is what you have so far:

/*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++;
}

/**/





最好显示整个功能,你谈到CMemo但不显示任何类型的变量。 CDBVariant是一个对CString无用的DB文件IO函数。备注是文本样式变体数据类型。检查备注结构(如果有),并更好地了解它。



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.


这篇关于如何从具有Memo数据类型字段的MS Access数据库(mdb文件)获取值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆