how can i validate a new line?
my problem:
When i add a new line (for example a orderline) then i will check the productnumber. Is the Productnumber wrong then i will remove this line before i do an update or insert on the database.
I tried this but it doesn't worked.
When i call db.Orderlines.DeleteOnSubmit(_CurrentOrderline)
then i became this message:
"SaveRecord: Cannot remove an entity that has not been attached."
Code: Select all
Private Sub iniOrderline()
Dim Orderlines = From l In db.Orderline _
Select l
myBindingSource.DataSource = Orderlines
AddHandler myBindingSource.ListChanged, AddressOf BindingSource_ListChanged
End Sub
Private Sub BindingSource_ListChanged(ByVal sender As Object, ByVal e As System.ComponentModel.ListChangedEventArgs)
If e.ListChangedType = System.ComponentModel.ListChangedType.ItemChanged AndAlso _
e.PropertyDescriptor.Name = "ProductNumber" Then
_CurrentOrderline = TryCast(Me.myBindingSource.List(e.NewIndex), Orderline)
If ProductExists(_CurrentOrderline.ProductNumber) Then
db.Orderlines.InsertOnSubmit(_CurrentOrderline)
db.SubmitChanges()
Else
'// product not exists
db.Orderlines.DeleteOnSubmit(_CurrentOrderline) '<- SaveRecord: Cannot remove an entity that has not been attached.
db.SubmitChanges()
End If
End If
End Sub
Marcus