GetChanges false positives, How to avoid?

E

entdevguy

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
 
M

Miha Markic [MVP C#]

Hi,

You might do an "if" before updating the value, something like:
if (ds.Table1.Col1 != TextBox1.Text)
 

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