Problems with DataView.RowFilter

  • Thread starter Thread starter Jack
  • Start date Start date
J

Jack

I have a DataView set up as following:

DataView dv = new DataView();
dv.Table = twsDS1.twsContractHdr;
dv.RowFilter = "AgencyID = '" + agency + "' AND NeedsStatus = 'I'";
int cnt = dv.Count;

In my test, this returns the expected value of "3" for the cnt of incomplete
items within the contract header table in the testdriver. If I then modify
one of the row needs status to "C" (completed) in the testdriver and rerun
the above, I expect to see "2" for this value... but it is still returning
the original value of 3.

I tried modifying to use a DataRow[] and foreach loop using a Select clause
using the same filter as above. It, too, loops three times after modifying a
row to "C". Displaying the text on each loop shows two are still "I" as
expected and the third "C" as NOT EXPECTED in that it should have been
filtered out in the Select.

What gives? Do I need to do an AcceptChanges?
 
Jack, check the value of NeedsStatus in the dattable, it sounds like the
edit isn't finished. I don't think AcceptChanges is what you want b/c
you'll lose all of your edits so if you call update afterward you won't have
anything sent back to the db. Are you rerunning the thing altogether or do
you have another function, it'd help if you could show how you were doing
the test.

--

W.G. Ryan, eMVP

Have an opinion on the effectiveness of Microsoft Embedded newsgroups?
Let Microsoft know!
https://www.windowsembeddedeval.com/community/newsgroups
 
William Ryan eMVP said:
it'd help if you could show how you were doing
the test.

The following code fragments, with the exception of using a DataRow array
rather than the DataView (result is the same for both) is what I am using.
The btnParcelComplete event sets Current, Prior, and Remption needs status.
If there are no further needs, the entire taxid is flagged as "C" (lhdr is a
DataRow in the twsDS1.twsContractHdr table). The test DataSet initially has
three "I" rows and the count in NoIncompleteTaxIds is accurate. When the btn
is clicked and the conditions meat in MofifyNeeds to reset one of the "I"
rows to "C", the count in NoIncompleteTaxIds should be reduced by 1 (i.e.,
2). Instead, cnt is STILL showing as 3 when lhdr.Cells["NeedsStatus"].Value
= "C" is met. The foreach loop shows two "I" and one "C"... so count should
have been 2 because "C" does not meet the Select criteria.

Code fragments are as follows:

private void btnParcelComplete_Click(object sender, System.EventArgs e)
{
[...]
ModifyNeeds();
}

private void ModifyNeeds()
{
[...]
if ( txtSCurrNeeds.Text != "Y" &&
txtSPriorNeeds.Text != "Y" &&
txtMRedemNeeds.Text != "Y" )
{
lhdr.Cells["Redemption"].Value = "*";
lhdr.Cells["NeedsStatus"].Value = "C";
}
NoIncompleteTaxIds();
}

private bool NoIncompleteTaxIds()
{
string agency = r.AgencyID;

DataRow[] tstRows = twsDS1.twsContractHdr.Select("AgencyID = '" + agency
+ "' AND NeedsStatus = 'I'");
int cnt = tstRows.Length;

foreach (DataRow tst in tstRows)
{
string taxid = tst["TaxId"].ToString();
string status = tst["NeedsStatus"].ToString();
}

txtMIncompleteCnt.Text = cnt.ToString();

if (cnt > 0)
return false;
else
return true;
}
 
Is lhdr a Grid? If so, then call .EndEdit. You can verify that it's still
in edit mode by testing for HasChanges...
debug.Assert(mydataSet.HasChanges);
I'm guessing it's comign back as false.

Let me know if not.

--
W.G. Ryan MVP Windows - Embedded

http://forums.devbuzz.com
http://www.knowdotnet.com/dataaccess.html
http://www.msmvps.com/williamryan/
Jack said:
William Ryan eMVP said:
it'd help if you could show how you were doing
the test.

The following code fragments, with the exception of using a DataRow array
rather than the DataView (result is the same for both) is what I am using.
The btnParcelComplete event sets Current, Prior, and Remption needs status.
If there are no further needs, the entire taxid is flagged as "C" (lhdr is a
DataRow in the twsDS1.twsContractHdr table). The test DataSet initially has
three "I" rows and the count in NoIncompleteTaxIds is accurate. When the btn
is clicked and the conditions meat in MofifyNeeds to reset one of the "I"
rows to "C", the count in NoIncompleteTaxIds should be reduced by 1 (i.e.,
2). Instead, cnt is STILL showing as 3 when lhdr.Cells["NeedsStatus"].Value
= "C" is met. The foreach loop shows two "I" and one "C"... so count should
have been 2 because "C" does not meet the Select criteria.

Code fragments are as follows:

private void btnParcelComplete_Click(object sender, System.EventArgs e)
{
[...]
ModifyNeeds();
}

private void ModifyNeeds()
{
[...]
if ( txtSCurrNeeds.Text != "Y" &&
txtSPriorNeeds.Text != "Y" &&
txtMRedemNeeds.Text != "Y" )
{
lhdr.Cells["Redemption"].Value = "*";
lhdr.Cells["NeedsStatus"].Value = "C";
}
NoIncompleteTaxIds();
}

private bool NoIncompleteTaxIds()
{
string agency = r.AgencyID;

DataRow[] tstRows = twsDS1.twsContractHdr.Select("AgencyID = '" + agency
+ "' AND NeedsStatus = 'I'");
int cnt = tstRows.Length;

foreach (DataRow tst in tstRows)
{
string taxid = tst["TaxId"].ToString();
string status = tst["NeedsStatus"].ToString();
}

txtMIncompleteCnt.Text = cnt.ToString();

if (cnt > 0)
return false;
else
return true;
}
 
William Ryan eMVP said:
Is lhdr a Grid? If so, then call .EndEdit. You can verify that it's still
in edit mode by testing for HasChanges...
debug.Assert(mydataSet.HasChanges);
I'm guessing it's comign back as false.

It's bound to an Infragistics UltraWinGrid... and calling ExitEditMode and
UpdateData on it doesn't seem to make a difference.

What is confusing is the DataTable row column IS showing the expected value
("C") in the test loop so the bound data is being propgated to the
underlying DataSet, it's just not filtering correctly in the Select (It
shouldn't be showing up at all.).
 
Never mind... found the problem. Forgot to do call the UpdateData method on
the grid.

Still curious as to why it was showing up as modified in the foreach loop
though. Must be some state nuance in the DataSet table that I don't
understand.
 
Back
Top