Can I change the query for a grid at runtime?
You have to close the recordset and reopen it.
Example:
void CGxqueryView::OnRecordNewquery()
{
// Display dialog, so that user can
// enter the query string
CMyQueryDialog dlg;
// disable ReadOnly, Use CursorLibray, Exclusive checkbox
dlg.m_bOpenDatabase = FALSE;
// reuse last query string
dlg.m_sSQLString = m_pSet->GetSqlQuery();
if (dlg.DoModal() == IDOK)
{
// Cancel pending changes and close recordset
UndoRecord();
m_pSet->Close();
// Transfer query string and reopen recordset
m_pSet->SetSqlQuery(dlg.m_sSQLString);
OpenRecordset();
}
}