Adding new Rows to DataSet which is bound to controls

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

Guest

Hi,

This thing is giving me the sh** and there must be a
simple way of doing this:
I have a form with several bound controls (textboxes,
combos...).

What i want do do is add a new row. The form should show
all the controls empty, then user can fill in values and
by pressing 'Save', save it to the database.

In the constructor I do this:

CustomersDS.CustomersRow nr = ds1.Customers.NewCustomersRow
();
ds1.EnforceConstraints = false; //without this it'll bomb.
ds1.Customers.AddCustomersRow(nr);
this.BindingContext[ds1, "Customers"].Position =
ds1.Customers.Rows.Count;

In the Save button, this:

if(ds1.HasChanges())
sqlDataAdapter1.Update(ds1.GetChanges(););


For some reason I can see the newly added values in ds1
before I do the GetChanges(), but if I check the values in
the DataRow of the DataSet created by ds1.GetChanges(),
all fields are empty.

Would be very grateful if anyone can point out what I'm
doing wrong.

Thanks for your help!
Dom
 
this.BindingContext[ds1, "Customers"].Position =
ds1.Customers.Rows.Count;

_All_ arrays in .NET are zero based. Set the postition to
ds1.Customers.Rows.Count - 1 and you should be good to go.

Cheers,
Dave
 
Thnx for your reply, Dave

The Rows.Count was a bit of a red-herring. The problem is
that the new rows are in the dataset after i do the
GetChanges(), but the fields are empty.

Cheers,
Dominic
 
Back
Top