Solved

CDaoQuerydef and CDaoRecordset; running a query help

Posted on 1998-08-26
2
506 Views
Last Modified: 2013-11-19
I'm trying to do a simple search through my database.  I created a query in Access called "Simple Search".  The Criteria is: [Title] like [Search String].  Title is a field in the database.  Search String is a parameter that is set by my program.  This is my code:


//m_pDaoWorkspace and m_pDaoDatabase have already been created

CDaoQueryDef q(m_pDaoDatabase);
q.Open("Simple Search");
int isRet = q.GetReturnsRecords(); // this returns 1
int param = q.GetParameterCount(); // this returns 1
CDaoParameterInfo info;
q.GetParameterInfo(0,info);  // the 1 param = Search String

q.SetParamValue("Search String",COleVariant("*Uranium*"));
//I hope I have done this right.This might explain problem

CMyRecordset *r; // derived from CDaoRecordset
r = new CMyRecordset( m_pDaoDatabase );

if( ! r->IsOpen( ))
{
   try
   {
      r->Open(&q);
   }
   catch( CDaoException* eDaoException )
   {
      eDaoException->Delete( );
      return FALSE;
   }
}
int recs = r->GetRecordCount();

This last line is the problem.  it returns 0.


If I do not pass the CQueryDef pointer to the Open function of CMyRecordset and just open it as a normal dynset recordset GetRecordCount returns 220 as it should.  There are 220 records in the database.  So the problem lies in my CQueryDef usage and most likely, I figure how I set the parameter.  Because if I run the query in MS-Access with the same value as I set it in my program it returns some 50 records.

I'd really appreciate any information I could get about things to look at.
0
Comment
Question by:LukeSkywalker
2 Comments
 
LVL 2

Accepted Solution

by:
milenvk earned 200 total points
ID: 1321329
Yes the problem is where you suppose it is. DAO uses ANSI character strings, but COleVariant converts your "*Uranium*" parameter to BSTR (i.e. wide character string). Here's what you should do to fix the problem. Replace the line:

q.SetParamValue("Search String",COleVariant("*Uranium*"));

with

q.SetParamValue("Search String",COleVariant("*Uranium*", VT_BSTRT));

See VT_BSTRT is the BSTR type that uses ANSI convension. VT_BSTR is the one that's using the wide character convension and it is set by the COleVariant contrustor by default.

0
 

Author Comment

by:LukeSkywalker
ID: 1321330
You suggestion worked to solve that problem.  Thank you!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to calculate times for developing software? 8 65
Generic progress indicator 6 113
Expand macro to ask for filename column 8 37
Excel file not created as expected 7 49
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now