TableAdapter.Update not working but no exception thrown

  • Thread starter Thread starter J055
  • Start date Start date
J

J055

Hi

I can't figure this one out. I'm using TableAdapters quite successfully with
the rest of my app but I have one where the insert just doesn't work when
the TableAdapter.Update(TypedDataTable) is called.

When I set the break point on the method I can see that it initializes the
adapter in the DataSet.Designer.cs file. Can someone suggest how I can work
out what's going wrong? I've recreated the table adapter in the xsd wizard
page but it's always the same. No exception is thrown but the update method
is definitely called and the insert stored procedure works too. The code is

ScsDataSet.NotificationEmailsDataTable notifyTbl = new
ScsDataSet.NotificationEmailsDataTable();
ScsDataSet.NotificationEmailsRow notifyRow =
notifyTbl.NewNotificationEmailsRow();

// account.AccountID retrieved from another TA update
notifyRow.AccountID = account.AccountID;
notifyRow.CreateDate = DateTime.Now;
notifyRow.ModifyDate = DateTime.Now;
notifyRow.NotifyType = 0;
notifyRow.Email = email.Trim();
notifyRow.IsLogin = true;

// row is populated above ok
NotificationEmailsTA.Update(notifyTbl); // notifyRow.EmailID == 0 and the
record is not inserted
if (notifyRow.EmailID == 0)
throw new ApplicationException("NotificationEmailsTA not inserting");

Thanks
Andrew
 
Have you verified that the table has Changes? If not, then there's nothing
to update
 
It is not enough to crate a new row, you have to add it to collection, too.
Try something like notifyTable.AddNotificationsEmailsRow(notifyRow) after
you populate the row.
 
How embarrassing. I thought it must be something simple. I couldn't see the
wood for the trees.

Thank you so much.
Andrew
 
Hi Andrew,

I think what Miha means is that we have to add the row into the table
collection before we update table to database.

For example:
//Create the table
ScsDataSet.NotificationEmailsDataTable notifyTbl = new
ScsDataSet.NotificationEmailsDataTable();

//Create the data row
ScsDataSet.NotificationEmailsRow notifyRow =
notifyTbl.NewNotificationEmailsRow();

//assign the value of row
notifyRow.AccountID = account.AccountID;
notifyRow.CreateDate = DateTime.Now;
notifyRow.ModifyDate = DateTime.Now;
notifyRow.NotifyType = 0;
notifyRow.Email = email.Trim();
notifyRow.IsLogin = true;

//***Note: we need add this row into table
notifyTbl.AddNotificationsEmailsRow(notifyRow);

//update the table to database.
NotificationEmailsTA.Update(notifyTbl);

Every time we create a new row from a table, we should add this row into
this table again.
Please try the above code and let me know whether or not it is what you
need. I'm glad to work with you.
Have a great day!
Wen Yuan
 
Back
Top