Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 418
  • Last Modified:

m_strFilter question.

I have 2 indexes STKI and DOCI. I need to Filter for the 2nd index only,ie all records with DOCN (2nd param) regardless of the STK (1st param). What do I substitute for the m_strSTKParam.  I have tried inserting ALL and
*, and other combinations.  MSDN Documentation does not address this specifically. If I only put the second parameter in the strFilter and not the rest it also doesn't work because the recordset has 2 parameters so the strFilter is supposed to have both Parameters. The question is what do I put for the 1st parameter?

 DET.m_strFilter="STK= ?  AND DOCN= ?";

(If I I specify a value for the 1st and 2nd Param then there is no problem so that is not the question.)


1 Solution
Hi binstar,
Try doing this.

if you want only the sencond parametsr, then set the filter only for the second parameter like below, it will work.

DET.m_strFilter="DOCN= " + m_getdoc;

Try it, All the best.
or you can try the following

DET.m_strFilter="STK LIKE ?  AND DOCN= ?";

not sure but maybe ..
binstarAuthor Commented:
I think both of these approaches should work, but they are not.  I know that if I specify a value in single quotes for the second parameter only it works
ie DET.m_strFilter="DOCN='123'"
But why is it not working with the placeholder?
The answer to this question is quite simple.   When the first param is empty, the resulting WHERE clause is invalid.  The SQL Server will see something like:

     SELECT * FROM MyTable WHERE STK=  AND DOCN= 'someValue'

which is obviously an error.  The simple and intiutive solution is to not use the STK=? parm when you don't want to use STK in the search criteria!

But there is another workaround if you can't figure out how to do that.  Use

     SELECT * FROM MyTable WHERE STK=STK  AND DOCN= 'someValue'

I see no way to do that with query parameters, because the driver will treat it like a quoted string.  But parameters are just a pain to work with anyway.  Just get rid of the parameterss altogetherand  format the m_strFilter string as desired:

        if (  m_getStk !=  "" ) {
                DET.m_strFilter.Format( "STK= '%s'  AND DOCN= '%s'", m_getStk, m_getdoc );
        else {
                DET.m_strFilter.Format( "DOCN= '%s'", m_getdoc );
                // alternative, foolish but functional
                // DET.m_strFilter.Format( "STK=STK  AND  DOCN= '%s'", m_getdoc );

-- Dan

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now