Database filtering with active x controls
genereal active x controls provided by Ms. Visual C++ 6.0,
wich are Ado data control(ole-db) and Microsoft data grid.
The Objective of this simple program is to implement
genereal active x controls provided by Ms. Visual C++ 6.0,
wich are Ado data control(ole-db) and Microsoft data grid.
My Application is quit simple, it was built by using
MFC Application Wizard and I derived the View from
CFormView after that just put the active x controls on
the form as you might see on the demo app.
Set the database connection property for the Ado data controls
to Ms.Access database "titles_db" (included in demo app)
or your sql server database "pubs" change the record source property
to AcmdText type this SQL statement "select * from titles"
Set the data source property for Ms.Data grid to "adodc1"
By Using MFC Class Wizard we can asign a variable or object
for this two Active x controls.
The database filtering mechanism is actualy done by changing the
property of this controls object at run time.
void CSantoView::OnSearch()
{
char searchvalue[20];
char searchcolumn[20];
char recordsource[100];
char expression[10];
UpdateData(TRUE);
strcpy(searchvalue,(LPCSTR) m_value);
strcpy(searchcolumn,(LPCSTR) m_column);
strcpy(expression,(LPCSTR)m_expression);
sprintf(recordsource,"select * from titles where %s %s %s",m_column,m_expression,m_value);
m_ado.SetConnectionString("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\TEMP\\Santo\\Debug\\titles_db.mdb;Persist Security Info=False");
//change this database path with your own database path
m_ado.SetRecordSource((LPCSTR)recordsource);
m_ado.SetCommandType(1);
m_ado.Refresh();
}
notes:
If the search value (expression) that we put are characters,
dont forget to enclosed with ' ' (single quotation) before
start seacrching.
santo fernando saputra manurung

