Hello,
after successfully building wxbda and dba, I'm trying to display the
query result in a DataGrid. My Problem is, that there is only the last
query result in each row of my DataGrid.
I'm using following code:
wxString qryresult;
wxdba::SQL selec(wxdba::SQL(_T("SELECT * FROM
mydatabase")).into(qryresult));
std::auto_ptr<wxdba::DbResult> res(ar-
>GetIStream().SendQuery(selec));
while(res->FetchRow())
{
for(int i = 0; i < RowCount; i++)
{
for( int a = 0; a < ColumnCount; a++)
{
grd_Table->SetCellValue(i,a,qryresult);
}
}
}
> Hello, > after successfully building wxbda and dba, I'm trying to display the > query result in a DataGrid. My Problem is, that there is only the last > query result in each row of my DataGrid.
This will read X columns from mydatabase table and stores value of the last one into qryresult. You need to provide as many variables as columns that you fetch from the table, e.g.:
wxString a,b,c;
wxdba::SQL select(wxdba::SQL(_T("SELECT a,b,c FROM mydatabase")).into(a).into(b).into(c));
> while(res->FetchRow()) > { > for(int i = 0; i < RowCount; i++) > { > for( int a = 0; a < ColumnCount; a++) > { > grd_Table->SetCellValue(i,a,qryresult); > } > } > }
If you do not know the number of columns then use res->Columns() and res->GetString(int) to get values instead of into():
while(res->FetchRow()) { for (int i = 0; i < res->Columns(); i++) { grd_Table->SetCellValue(i,a,res->GetString(i)); }
I changed my code to:
int b = 0;
while(res2->FetchRow())
{
for( int a = 0; a < res->Columns(); a++)
{
grd_Table->SetCellValue(b,a,res2->GetString(a));
}
b++;
}
and it works now!
There's one question remaining: How can i Display additional
character? Like öäü etc.?
The Cell is empty, when the value contains an additional character.
> I changed my code to: > int b = 0; > while(res2->FetchRow()) > {
> for( int a = 0; a < res->Columns(); a++) > { > grd_Table->SetCellValue(b,a,res2->GetString(a)); > } > b++; > }
> and it works now! > There's one question remaining: How can i Display additional > character? Like öäü etc.? > The Cell is empty, when the value contains an additional character.
It depends on your database. The key is to set the same enconding in SetConversionSpecs as your database uses.
(default is UTF8, so if your database uses UTF-8 encoding then it should work out of the box)