Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Table Adapter Update - not updating

Status
Not open for further replies.

NSNewey

Programmer
Joined
Jun 29, 2005
Messages
125
Location
GB
Hi,

I have a vb 2005 winforms data application that connects to an Access database...

I am having trouble updating the record with null values so I have entered this code before the update is called...

If Me.txtDate.Text = String.Empty Then
Me.TEnqBindingSource.Current.row.Item("OrderDate") = DBNull.Value
Else
Me.TEnqBindingSource.Current.row.Item("OrderDate") = Me.txtDate.Text
End If

Me.Validate()
Me.TEnqBindingSource.EndEdit()
Debug.Print Me.TEnqTableAdapter.Update(Me.TradeBaseDataSet.tEnq)

When I change the textbox holding the date to "" it updates fine (returns 1 on the debug.print) as long as no other fields have changed. If I change the date to "" and change another field to a different value, the update returns 0 (it didn't update)

Any ideas please?
 
It is often that the AcceptChanges method called "accidently". For example:
Me.TradeBaseDataSet.tEnq.AcceptChanges

AcceptChanges method will change the current RecordState to Unmodified. Check it out first, then we'll see for further possibility.

Regards.
 
Hi Mansii

I am not calling AcceptChanges anywhere.

Is the line Me.TEnqBindingSource.Current.row.Item("OrderDate") = DBNull.Value
calling AcceptChanges implicitly

Any more help would be appriciated.

Neil
 
I'm affraid not.
From what I have experienced, the Update method throws me an exception if it returns 0, except the ContinueUpdateOnError property is set to True.
If you did this, remove the line. Then put it in a Try-Catch block. Let's see if it throws an error, too.
Code:
Try
   Me.TEnqTableAdapter.Update(Me.TradeBaseDataSet.tEnq)
Catch ex as Exception
   Msgbox ex.ToString
End Try

 
Sorry but I can't see where to set the ContinueUpdateOnError to true.
 
My mistake. It belongs to DataAdapter.
Now, here's a note from MSDN:
Because attempting to update a data source with the contents of a dataset can result in errors, you should place the code that calls the adapter's Update method inside of a try/catch block.

Continued by
The exact procedure to update a data source can vary depending on your business needs, but your application should include the following steps:

Call the adapter's Update method within a try/catch block.

If an exception is caught, locate the data row that caused the error. For more information, see How to: Locate Rows that Have Errors.

Reconcile the problem in the data row (programmatically if possible, or by presenting the invalid row to the user for modification), and then reattempt the update (HasErrors, GetErrors).

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top