I was curious if anybody know of a way to avoid false positives while
using the GetChanges method. In most of my updateable aspx pages I
have text/ddl/checkboxes that are populated from the existing data
that the user can change, then hit the save/update button. When the
save/update button is clicked the dataset is updated from the controls
values regaurdless if the values in the controls have changed or not.
Such as

ds.Table1.Col1 = TextBox1.Text; // set whether text has changed or
not.
ds.Table1.Col2 = TextBox2.Text;

The problem arises when a user hits the save/update button without
changing anything on the page. This means that all the values in the
dataset get set to exactly what they were before; however, the
GetChanges returns rows with no real changes in them.

Take the following code. The last GetChanges always returns 1 row
even though no values in the row have changed.

Dataset1 ds = new Dataset1();
Dataset1.UsersRow r = ds.Users.NewUsersRow();
string s = "asdf";

r.UserName = s;
r.UserID = 1;
ds.Users.Rows.Add(r);
ds.AcceptChanges();

DataTable dt = ds.Users.GetChanges();
if(dt != null)
Console.WriteLine("# of changed rows " + dt.Rows.Count);

ds.Users[0].UserName = s; // change the value to exactly what it
was.
dt = ds.Users.GetChanges();
if(dt != null)
Console.WriteLine("# of changed rows " + dt.Rows.Count);

Any help is appreciated,
EntDevGuy

Re: GetChanges false positives, How to avoid? by Miha

Miha
Fri Dec 03 02:04:52 CST 2004

Hi,

You might do an "if" before updating the value, something like:
if (ds.Table1.Col1 != TextBox1.Text)
--
Miha Markic [MVP C#] - RightHand .NET consulting & development
SLODUG - Slovene Developer Users Group
www.rthand.com

"entdevguy" <bcutting@gmail.com> wrote in message
news:5c6ca5ff.0412021419.5a30b57e@posting.google.com...
>I was curious if anybody know of a way to avoid false positives while
> using the GetChanges method. In most of my updateable aspx pages I
> have text/ddl/checkboxes that are populated from the existing data
> that the user can change, then hit the save/update button. When the
> save/update button is clicked the dataset is updated from the controls
> values regaurdless if the values in the controls have changed or not.
> Such as
>
> ds.Table1.Col1 = TextBox1.Text; // set whether text has changed or
> not.
> ds.Table1.Col2 = TextBox2.Text;
>
> The problem arises when a user hits the save/update button without
> changing anything on the page. This means that all the values in the
> dataset get set to exactly what they were before; however, the
> GetChanges returns rows with no real changes in them.
>
> Take the following code. The last GetChanges always returns 1 row
> even though no values in the row have changed.
>
> Dataset1 ds = new Dataset1();
> Dataset1.UsersRow r = ds.Users.NewUsersRow();
> string s = "asdf";
>
> r.UserName = s;
> r.UserID = 1;
> ds.Users.Rows.Add(r);
> ds.AcceptChanges();
>
> DataTable dt = ds.Users.GetChanges();
> if(dt != null)
> Console.WriteLine("# of changed rows " + dt.Rows.Count);
>
> ds.Users[0].UserName = s; // change the value to exactly what it
> was.
> dt = ds.Users.GetChanges();
> if(dt != null)
> Console.WriteLine("# of changed rows " + dt.Rows.Count);
>
> Any help is appreciated,
> EntDevGuy