Using a Parameterized Query

Hi,
I try a simple example that retrieves records with an age field from a table in a Microsoft Access database:

#include <atldbcli.h>

CDataSource connection;
CSession session;
CCommand<CAccessor<CArtists> > artists;

connection.Open(CLSID_MSDASQL, "NWind", "sa", "");
session.Open(connection);

// Set the parameter for the query
artists.m_nAge = 30;
artists.Open(session, "select * from artists where age > ?");

// Get data from the rowset
while (artists.MoveNext() == S_OK)
{
cout << artists.m_szFirstName;
cout << artists.m_szLastName;
}

The user record, CArtists, looks like this:

class CArtists
{
public:
// Data Elements
CHAR m_szFirstName[20];
CHAR m_szLastName[30];
short m_nAge;

// output binding map
BEGIN_COLUMN_MAP(CArtists)
COLUMN_ENTRY(1, m_szFirstName)
COLUMN_ENTRY(2, m_szLastName)
COLUMN_ENTRY(3, m_nAge)
END_COLUMN_MAP()

// parameter binding map
BEGIN_PARAM_MAP(CArtists)
COLUMN_ENTRY(1, m_nAge)
END_PARAM_MAP
};

the example works but if I try the same with CHAR m_szFirstName:

BEGIN_PARAM_MAP(CArtists)
COLUMN_ENTRY(1, m_szFirstName)
END_PARAM_MAP
};

strcpy(artists.m_szFirstName, "a");
artists.Open(session, "select * from artists where name like '%?%' ");

I have no result...
What can I do??

thanks,
Mreclo Modolo
[1565 byte] By [mrmodolo] at [2007-11-18 19:08:50]
# 1 Re: Using a Parameterized Query
Try

strcpy(artists.m_szFirstName, "%a%");
artists.Open(session, "select * from artists where name like ?);
Bob Sheep at 2007-11-9 13:37:23 >