DataView.RowFilter problem

D

David Young

Hey folks, having a bit of a problem here and probably just need another
set of eyes to look at it.

I have an existing dataset, for the sake of this discussion, I'll call it
myDataSet. Please review the following:

[code snippit] ( C# )
string planType = this.ux_planType.SelectedValue;
string dedcd = this.ux_deductionCode.Text.Trim().ToUpper();
DataView dv = new DataView(myDataSet.myTable);
dv.RowFilter = "PLAN_TYPE = '" + planType + "' AND DEDCD = '" + dedcd + "'";
if(dv.Table.Rows.Count == 0)
{
// do some work here
return;
}

The problem is, the inner program loop never runs, becuase the
dv.Table.Rows.Count always returns > 0. I set a break point for the
debugger and stepped throught it. When I do, I can look at the Rows in the
DataView, but none of the match my RowFilter criteria that I set above. I
even put a debug message to write out the dv.Table.Rows.Count to the output
window before and after setting the RowFilter property, but the count
doesnt' change after applying the RowFilter.

Can anyone see why the RowFilter is not working?
 
W

W.G. Ryan - MVP

you are using dv.Tables.Rows.Count which will always be the number of rows
in the table. Use dv.Count to get the number of the rows in the view -
which are the ones that match the rowfilter. If that doesn't fix it, let me
know but that should do it.
 
D

David Young

Thanks Bill,

I knew it was something stupid like that. :) I had checked against some
other code that was working and for the life of me, I coudn't see what was
wrong. These old tired eyes just couldn't see.

W.G. Ryan - MVP said:
you are using dv.Tables.Rows.Count which will always be the number of rows
in the table. Use dv.Count to get the number of the rows in the view -
which are the ones that match the rowfilter. If that doesn't fix it, let me
know but that should do it.
David Young said:
Hey folks, having a bit of a problem here and probably just need another
set of eyes to look at it.

I have an existing dataset, for the sake of this discussion, I'll call it
myDataSet. Please review the following:

[code snippit] ( C# )
string planType = this.ux_planType.SelectedValue;
string dedcd = this.ux_deductionCode.Text.Trim().ToUpper();
DataView dv = new DataView(myDataSet.myTable);
dv.RowFilter = "PLAN_TYPE = '" + planType + "' AND DEDCD = '" + dedcd +
"'";
if(dv.Table.Rows.Count == 0)
{
// do some work here
return;
}

The problem is, the inner program loop never runs, becuase the
dv.Table.Rows.Count always returns > 0. I set a break point for the
debugger and stepped throught it. When I do, I can look at the Rows in
the
DataView, but none of the match my RowFilter criteria that I set above. I
even put a debug message to write out the dv.Table.Rows.Count to the
output
window before and after setting the RowFilter property, but the count
doesnt' change after applying the RowFilter.

Can anyone see why the RowFilter is not working?
 
W

W.G. Ryan - MVP

I've done the same thing more times than I'll admit to publicly ;-). Glad
to have helped.
David Young said:
Thanks Bill,

I knew it was something stupid like that. :) I had checked against some
other code that was working and for the life of me, I coudn't see what was
wrong. These old tired eyes just couldn't see.

W.G. Ryan - MVP said:
you are using dv.Tables.Rows.Count which will always be the number of
rows
in the table. Use dv.Count to get the number of the rows in the view -
which are the ones that match the rowfilter. If that doesn't fix it, let me
know but that should do it.
David Young said:
Hey folks, having a bit of a problem here and probably just need another
set of eyes to look at it.

I have an existing dataset, for the sake of this discussion, I'll call it
myDataSet. Please review the following:

[code snippit] ( C# )
string planType = this.ux_planType.SelectedValue;
string dedcd = this.ux_deductionCode.Text.Trim().ToUpper();
DataView dv = new DataView(myDataSet.myTable);
dv.RowFilter = "PLAN_TYPE = '" + planType + "' AND DEDCD = '" + dedcd +
"'";
if(dv.Table.Rows.Count == 0)
{
// do some work here
return;
}

The problem is, the inner program loop never runs, becuase the
dv.Table.Rows.Count always returns > 0. I set a break point for the
debugger and stepped throught it. When I do, I can look at the Rows in
the
DataView, but none of the match my RowFilter criteria that I set above. I
even put a debug message to write out the dv.Table.Rows.Count to the
output
window before and after setting the RowFilter property, but the count
doesnt' change after applying the RowFilter.

Can anyone see why the RowFilter is not working?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top