I have a frame that makes data insertion into a database, with a grid that shows this data. This grid must be updated:
- when the frame is shown;
- when "record" button is pressed and recording occur succesfully;
For this, I need also to clear the grid, before updating it.
Take a look:
This is the function that execs a sql selection command and distribute the data extracted from database to the grid:
Code: Select all
void CadCidade::SelecionarGrid()
{
Grid1->ClearGrid();
conecta* objgrid = new conecta();
PGresult *resGrid;
resGrid = PQexec(objgrid->conn, "select * from cadcidade");
int numlinha = PQntuples(resGrid);
int numcoluna = PQnfields(resGrid);
Grid1->InsertRows(1, numlinha, true);
for (int y = 0; y < numcoluna; y++)
{
int x = 0;
for ( x = 0; x < numlinha; x++)
{
char* valor = PQgetvalue(resGrid, x, y);
wxString valorS(valor, wxConvISO8859_1);
Grid1->SetCellValue(x,y, valorS);
}
}
}
This code I posted is not working correctly. After recorded the data, the number os lines becomes duplicated and the new record only appears when the frame is showed again. I think ClearGrid() is not in the right place, or I`m using it wrong way.
Can anyone help me?
Thanks everybody!!