15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


Strange Behavior of CDaoRecordSet::Seek

wallacechoi@hactl.com.hk
Tuesday, January 28, 1997

     Environment: MSVC 4.0, Win 95
     
     Hi MFC Pros,
     
        I am having problem in using the Seek function of 
     DaoRecordset(Table Mode). My program has different local tables with 
     different indexes. But the Seek function call worked correctly only 
     for those indexes that are not of the type Text.
     
     e.g. setA is a DaoRecordset with an int index, "IdxInt"
     
     TRY {
        int intVal = 99;
        ....
        setA.SetCurrentIndex("IdxInt");
        if ( setA.Seek("=", &COleVariant(intVal)) { //works correctly
             //do something ....
        }
     }
     CATCH (CDaoException, pEx) {
        .....
     }END_CATCH
     
     setB is a DaoRecordset with an string Index, "IdxStr"
     TRY {
     
        CString strVal = "xxxxx";
        ....
        setB.SetCurrentIndex("IdxStr");
        if ( setB.Seek("=", &COleVariant(strVal)) { //always return FALSE
             //do something ....
        }
     }
     CATCH (CDaoException, pEx) {
        .....
     }END_CATCH
     
     
        I have tried other Seek operators but they worked quite 
     unexpectedly. Did I init the COleVariant incorrectly?? How can I 
     verify the index was correctly built?? Any help is highly 
     apprecipated.
     
        Wallace, PEI



Jeremy H. Griffith -- jeremy@omsys.com
Wednesday, January 29, 1997

[Mini-digest: 3 responses]

On Tue, 28 Jan 1997 16:01:09 +0800, wallacechoi@hactl.com.hk wrote:

>     Environment: MSVC 4.0, Win 95
>        I am having problem in using the Seek function of 
>     DaoRecordset(Table Mode). My program has different local tables with 
>     different indexes. But the Seek function call worked correctly only 
>     for those indexes that are not of the type Text.

If you are using SQL Server, you cannot create an index on a field of type
"text" (or "bit", or "image").  So it may be that the index you think you
have does not exist.  You can index on "varchar" fields, but it's usually a
bad idea.  If you use a composite index, the sum of the lengths of the
columns (max 16) used in it cannot exceed 256 bytes.

--Jeremy
-----From: Tom Sears 

Hi Wallace

I think that your call to &COleVariant(strVal)) is not doing quite what
you want it to.   If you change it to &COleVariant(strVal, VT_BSTRT)) it
will do the right thing for you.  I am guessing that you don't have
UNICODE defined, and your original COleVariant(string) is getting
converted into a UNICODE string when you really want an ANSI string.  


	Tom

>------------------------------------------------------------------------
>-----------
>Tom Sears, tsears@unlimitedsolutions.com

>----------
>From: 	wallacechoi@hactl.com.hk[SMTP:wallacechoi@hactl.com.hk]
>Sent: 	Tuesday, January 28, 1997 3:01 AM
>To: 	mfc-l@netcom.com
>Subject: 	Strange Behavior of CDaoRecordSet::Seek
>
>     Environment: MSVC 4.0, Win 95
>     
>     Hi MFC Pros,
>     
>        I am having problem in using the Seek function of 
>     DaoRecordset(Table Mode). My program has different local tables
>with 
>     different indexes. But the Seek function call worked correctly
>only 
>     for those indexes that are not of the type Text.
>     
>     e.g. setA is a DaoRecordset with an int index, "IdxInt"
>     
>     TRY {
>        int intVal = 99;
>        ....
>        setA.SetCurrentIndex("IdxInt");
>        if ( setA.Seek("=", &COleVariant(intVal)) { //works correctly
>             //do something ....
>        }
>     }
>     CATCH (CDaoException, pEx) {
>        .....
>     }END_CATCH
>     
>     setB is a DaoRecordset with an string Index, "IdxStr"
>     TRY {
>     
>        CString strVal = "xxxxx";
>        ....
>        setB.SetCurrentIndex("IdxStr");
>        if ( setB.Seek("=", &COleVariant(strVal)) { //always return
>FALSE
>             //do something ....
>        }
>     }
>     CATCH (CDaoException, pEx) {
>        .....
>     }END_CATCH
>     
>     
>        I have tried other Seek operators but they worked quite 
>     unexpectedly. Did I init the COleVariant incorrectly?? How can I 
>     verify the index was correctly built?? Any help is highly 
>     apprecipated.
>     
>        Wallace, PEI
>
-----From: "Nayab Khan" 

Hi Wallace:

Since the default constructor of the COleVariant(string) is UNICODE you
must call the poorly documented function SetString. In the online help you
won't find it listed in the "members of COleVariant" however you can get to
it by searching.

Try the following:

  	COleVariant var;
	var.SetString(str,VT_BSTRT);

	setB.SetCurrentIndex("IdxStr");
	if ( setB.Seek("=", &var)
		...



----------
> From: wallacechoi@hactl.com.hk
> To: mfc-l@netcom.com
> Subject: Strange Behavior of CDaoRecordSet::Seek
> Date: Tuesday, January 28, 1997 2:01 AM
> 
>      Environment: MSVC 4.0, Win 95
>      
>      Hi MFC Pros,
>      
>         I am having problem in using the Seek function of 
>      DaoRecordset(Table Mode). My program has different local tables with

>      different indexes. But the Seek function call worked correctly only 
>      for those indexes that are not of the type Text.
>      
>      e.g. setA is a DaoRecordset with an int index, "IdxInt"
>      
>      TRY {
>         int intVal = 99;
>         ....
>         setA.SetCurrentIndex("IdxInt");
>         if ( setA.Seek("=", &COleVariant(intVal)) { //works correctly
>              //do something ....
>         }
>      }
>      CATCH (CDaoException, pEx) {
>         .....
>      }END_CATCH
>      
>      setB is a DaoRecordset with an string Index, "IdxStr"
>      TRY {
>      
>         CString strVal = "xxxxx";
>         ....
>         setB.SetCurrentIndex("IdxStr");
>         if ( setB.Seek("=", &COleVariant(strVal)) { //always return FALSE
>              //do something ....
>         }
>      }
>      CATCH (CDaoException, pEx) {
>         .....
>      }END_CATCH
>      
>      
>         I have tried other Seek operators but they worked quite 
>      unexpectedly. Did I init the COleVariant incorrectly?? How can I 
>      verify the index was correctly built?? Any help is highly 
>      apprecipated.
>      
>         Wallace, PEI




| Вернуться в корень Архива |