CDatabase connection;
CString connstr("DSN=MyODBC");
TCHAR strsql[1024];
_snprintf(strsql, 1204, "select pid, name, pwd from probe where pid = ?"); // ???????????????????????try
{
if (connection.OpenEx(connstr), CDatabase::openReadOnly | CDatabase::noOdbcDialog)
{
CRecordset rs(&connection);
if (rs.Open(AFX_DB_USE_DEFAULT_TYPE, strsql))
{
while (!rs.IsEOF())
{
// ......
rs.MoveNext();
}
rs.Close();
}
connection.Close();
}
}
catch (CDBException* e)
{
printf(e->m_strError);
}上面标上问号的一行用了where pid = ?,请问这种预处理的语句应该怎样帮定参数?
请教,多谢!!!!!!
CString connstr("DSN=MyODBC");
TCHAR strsql[1024];
_snprintf(strsql, 1204, "select pid, name, pwd from probe where pid = ?"); // ???????????????????????try
{
if (connection.OpenEx(connstr), CDatabase::openReadOnly | CDatabase::noOdbcDialog)
{
CRecordset rs(&connection);
if (rs.Open(AFX_DB_USE_DEFAULT_TYPE, strsql))
{
while (!rs.IsEOF())
{
// ......
rs.MoveNext();
}
rs.Close();
}
connection.Close();
}
}
catch (CDBException* e)
{
printf(e->m_strError);
}上面标上问号的一行用了where pid = ?,请问这种预处理的语句应该怎样帮定参数?
请教,多谢!!!!!!
int i_id=你要的数字;
_snprintf(strsql, 1204, "select pid, name, pwd from probe where pid = %d",i_id); 如果是字符型.则:
int i_id=你要的数字;
_snprintf(strsql, 1204, "select pid, name, pwd from probe where pid = '%d'",i_id);
还是需要用预处理语句多谢!