PDA

View Full Version : QSqlTableModel



codeman
24th April 2009, 10:57
Hello there,

I have one problem in setting the filter from the above metioned object. So I have an QSqlTableModel and when I set my filter like this (line 7)


ValidToFilter->addItem("9999-12-31 23:59:59");
QString product = ProductFilter->currentText();
QString date = ValidToFilter->currentText();
QString eingabeFilter = "vcProductID='"+product+"'";
QString validationFilter = "dtValidTo='"+date+"'";
QString price = "dcPrice='0.200'";
model->setFilter( eingabeFilter +" and "+dcPrice);

everything is ok with multiple filter argument but when I change the second filter argument to this


model->setFilter( eingabeFilter +" and "+validationFilter );
view->setModel(model);


my view is empty. The second filterargument is an Datetime type on the mssql server table
So what do I wrong I have to filter the column on the sql server. For example this is one representativ entry in the column with datetime type : 9999-12-31 23:59:59.000

anybody some idea???

mazurekwrc
24th April 2009, 12:12
maybe here


QString date = ValidToFilter->currentText();

you get 9999-12-31 23:59:59 not 9999-12-31 23:59:59.000
so change


QString validationFilter = "dtValidTo='"+date+"'";

to


QString validationFilter = "dtValidTo like '"+date+"%'";

codeman
24th April 2009, 12:48
thank you.

So I change it in your way. now my view is not empty but in my datetime column there are some wrong filter elements. I choose 9999-12-31 23:59:59.000 as filter but there are also elements like this 30.06.2008 23:59:59 or see attachment for more detail ....

mazurekwrc
24th April 2009, 13:09
do you use


model->select();

after setFilter ?

codeman
24th April 2009, 13:37
Yes I do. This is the actual code



void TableEditor::refresh()
{
QString product = ProductFilter->currentText();
QString date = ValidToFilter->currentText();
QString eingabeFilter = "vcProductID='"+product+"'";
QString validationFilter = "dtValidTo like '"+date+"%'";
model->setFilter( eingabeFilter +" and "+validationFilter );
model->select();
view->setModel(model);
}


It seems that the second filter argument don´t grab correctly ?????

codeman
24th April 2009, 13:43
So I solve the problem: It must be



QString validationFilter = "dtValidTo= convert (datetime,'"+date+"',120)";

codeman
27th April 2009, 12:57
But I have one question.

When I set the strategy from my SqlTableModel on manual, I have problems when I change a column with the mssql datatype Datetime on the server on submitting the datas.

For example in my model one entry in the column is 31.12.2008 23:50:59 and when I change something and try to submit it occurs an error.

What kind of problem I have to solve here???

codeman
4th May 2009, 11:04
Hello friends I locate the problem exactly now. It ist a Datetime field overflow.

The entry in the column is 9999-12-31 23:59:59 and whne I try to change it and submit it occurs the field overflow error.

The MsSql server holds this value in the database but why it occurs the mentioned error.??