Bizarre behavior of DataView

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a DataView where I am trying to use “rowfilter†property to get a subset of base table rows. When my View gets created any rows which have “modified†or “added†row state are not returned in DataView although they satisfy my filter condition. I have tried to use all possible combinations of “DataViewRowState†enumeration values but nothing seems to be able to force returned DataView to include modified or added status rows. Has any body seen such behavior before or can any body think of any thing why it could be happening?
 
<"=?Utf-8?B?S3Jpc2huYSBUcmlwYXRoaQ==?=" <Krishna
I have a DataView where I am trying to use ?rowfilter? property to
get a subset of base table rows. When my View gets created any rows
which have ?modified? or ?added? row state are not returned in
DataView although they satisfy my filter condition. I have tried to
use all possible combinations of ?DataViewRowState? enumeration
values but nothing seems to be able to force returned DataView to
include modified or added status rows. Has any body seen such
behavior beforeor can any body think of any thing why it could be happening?

Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.
 
You seem to be using RowFilter and RowStateFilter interchangeable and they
aren't. I have some examples in my Efficiently using ADO.NET xxx articles
http://www.knowdotnet.com/articles/dataviews1.html Anyway, I'm not sure how
you are declaring the view b/c this is very stable in my experience.
Without seeing the code, it's impossible to tell you what's wrong. I'm
guessing that you may be setting one filter so when the other is set, you
are getting something other than what you expect - but this is just a guess.
Post the code and that should shed some light on the situation.

--

W.G. Ryan, eMVP

Have an opinion on the effectiveness of Microsoft Embedded newsgroups?
Let Microsoft know!
https://www.windowsembeddedeval.com/community/newsgroups
Krishna Tripathi said:
I have a DataView where I am trying to use "rowfilter" property to get a
subset of base table rows. When my View gets created any rows which have
"modified" or "added" row state are not returned in DataView although they
satisfy my filter condition. I have tried to use all possible combinations
of "DataViewRowState" enumeration values but nothing seems to be able to
force returned DataView to include modified or added status rows. Has any
body seen such behavior before or can any body think of any thing why it
could be happening?
 
Hi Krishna

I read it in this way,
The BeginEdit method is called implicitly when the user changes the value of
a data-bound control; the EndEdit method is called implicitly when you
invoke the DataTable object's AcceptChanges method. While in this edit mode,
the DataRow stores representations of the original and new proposed values.
Therefore, as long as the EndEdit method has not been called, you can
retrieve either the original or proposed version by passing either .

What means for me
\\\
dt.Rows[9].BeginEdit();
// Change 10th row to Modified status
dt.Rows[9]["name"] = "timbuktu";
// Add one row so that its status is Added
DataRow dr2 = dt.NewRow();
dt.AcceptChanges();
///
However because that the code above is a little bit useless I think it would
be
\\\
dt.Rows[9].BeginEdit();
// Change 10th row to Modified status
dt.Rows[9]["name"] = "timbuktu";
// Add one row so that its status is Added
DataRow dr2 = dt.NewRow();
dt.Rows[9].EndEdit();
///
I hope this answers the question?

Cor
First of all many thanks for responses.

Please find attached some test code where I have been able to reproduce
problem. I have called "BeginEdit()" on a row which I expect to be part of
my returned dataview as it will be bound to a grid in actual application
when I will try to create this view and according to MSDN documentation on
databound rows "BeginEdit" gets called implicitly until "acceptchanges()" is
not called.
As you can see in returned DataView I do not get any rows while I will expect 1.

Please let me know if I can make it clearer.

Here is sample code -

DataSet m_ds = new DataSet("testdataset");
DataTable dt = new DataTable("testtable");
DataColumn dc = new DataColumn("id",System.Type.GetType("System.Int32"));
dt.Columns.Add(dc);
dc = new DataColumn("name",System.Type.GetType("System.String"));
dt.Columns.Add(dc);
m_ds.Tables.Add(dt);

for (int i=0; i<10; i++)
{
DataRow dr = dt.NewRow();
dr[0] = i;
dr[1] = i.ToString() + "_name_".PadRight(100,'z');
dt.Rows.Add(dr);
}
dt.AcceptChanges();

// Call BeginEdit() on 10th row as it would be databound when view will be crated in actual application
dt.Rows[9].BeginEdit();
// Change 10th row to Modified status
dt.Rows[9]["Name"] = "timbuktu";
// Add one row so that its status is Added
DataRow dr2 = dt.NewRow();
dr2[0] = 100;
dr2[1] = "";
dt.Rows.Add(dr2);

// Dump Contents of Table
foreach (DataRow drThis in dt.Rows)
System.Diagnostics.Debug.WriteLine("ID = " + drThis["id"] + ", name = " + drThis["name"]);
// Now get View with rowfilter name = 'timbuktu'
DataView dv = new DataView(dt,"name = 'timbuktu'","",DataViewRowState.CurrentRows);
System.Diagnostics.Debug.WriteLine("Result of Test Application follows ------->");
System.Diagnostics.Debug.WriteLine("DataView row count = " + dv.Count.ToString());


And here is program output -

ID = 0, name = 0_name_zzzz
ID = 1, name = 1_name_zzzz
ID = 2, name = 2_name_zzzz
ID = 3, name = 3_name_zzzz
ID = 4, name = 4_name_zzzz
ID = 5, name = 5_name_zzzz
ID = 6, name = 6_name_zzzz
ID = 7, name = 7_name_zzzz
ID = 8, name = 8_name_zzzz
ID = 9, name = timbuktu
ID = 100, name =
Result of Test Application follows ------->
DataView row count = 0




Cor Ligthert said:
Hi Bill,

That is as Jon wrote, I am currious as well for this one.

:-)

Cor
 
Hi Krishna,

I pasted the first part from a page from MSDN, was not my writing, I thought
you were referring to that.

Then some answers to get it something further.

Maybe I say something stupid because you know that however when not than it
adds maybe something to your information, the dataview is only a view; it
has a reference to the used table in it.

Acceptchanges is a method you would almost never use. What it does is
setting the rowstates to not changed while it has taken the new changes (or
better as if, the changes are processed in the database). After that, you
cannot update anymore. In some scenario's you can use it after that you
have updated the dataset, although the dataadapter update does the
Acceptchanges itself when you use the original dataset.

BeginEdit/EndEdit is as well in my opinion seldom necessary only when you
want it to stop updating access by instance because you are updating a huge
dataset row by row.

I got the pasted information about the BeginEdit from this page.

http://msdn.microsoft.com/library/d...frlrfsystemdatadatarowclassbeginedittopic.asp

I hope this helps?

Cor
 
Hi Krishna,

I thought that I showed you that when you use beginedit the changes will not
affect in the dataview until the endedit is done. So I do not understand why
you want to use it, I asked you that before?

Cor
 
Hi Cor,

First of all my apologies if you think I am trying to ask / something unnecessarily. Actually with your answers (and I really do appreciate them) I have a better understanding of entire issue.

But I am still stuck at same question why I cannot access column values in DataView if BeginEdit has been called on row. According to documentation DataRowViewState.Current is suppose to give you current values for row. So when I am looking for them what internally prevent these values to be available to view? Is it some design issue or just it’s like that?

I hope you will understand that being a programmer for more than 10 years now, until I do not hit wall I cannot stop myself from digging.

Thanks,
Krishna
 
Hi Krishna,

Did you alreayd use the QuickWatch from the debugger with that you can as
you want figure a lot of things out.

Sometimes you have to set an extra reference (as I do it) because you cannot
see direct indexed objects, however it is great to see when and what is set
in the sequence of a program.

I hope this helps more than that I look up a direct answer for your question
because for me your question looks more that you want to know why than a
solution and than you have that tomorrow again.

Cor
 
Hi Cor,

I had tried possibly all possible options and was not able to get a handle on "BeginEdit" rows in my view and that is why I was puzzled that why the heck its not including specified rows event when explicitly specified.

Any way I guess its some MS design issue that I will never able to understand until MS decides to leak it in Knowledgebase.

I tweaked my UI to call EndEdit() and that gave me what I wanted ..

Any way thanks a lot for all help and appreciate your time and responses.

Thanks,
Krishna
 
Back
Top