Hey
Using the latest Version of dotConnect for mySQL
I have a table with one entity, which has AutoGenerated Value Option = True.
I insert a new Row of data with Linq and then I call the Refresh Method, so I get the autogenerated value, but this ends up with an error, that the entity cannot be NULL.
Please help - THX
Refresh Mode does not work as I want
My code:
Code: Select all
Try
Cursor.Current = Cursors.WaitCursor
Try
bsArtikelstamm.EndEdit()
Dim Details = From Query In LinqProvider.GetFirmendaten(True) Select Query
Dim ArtikelstammDetails As Artikelstammdetail
Dim Artikelstamm As Artikelstamm = bsArtikelstamm.Current
Artikelstamm.Icode = Nothing
Artikelstamm.Datseit = "1900-12-31"
SuchString = Artikelstamm.Artikelnr
For Each Detail As Firmendaten In Details
ArtikelstammDetails = New Artikelstammdetail With {.Firmenid = Detail.Id}
Artikelstamm.Artikelstammdetails.Add(ArtikelstammDetails)
Next
myDataContext.Artikelstamms.InsertOnSubmit(Artikelstamm)
LinqProvider.SaveDataContext(myDataContext)
Catch ex As Exception
If ex.InnerException.ToString.Contains("Duplicate Entry") = True Then
IntelliSoft.myMessageBox.OfficeBox.Show("Der von Ihnen eingegebene Artikel existiert bereits!", _
LinqProvider.MessageCaption, MessageBoxButtons.OK, _
IntelliSoft.myMessageBox.OfficeMessageBoxIcon.Error)
bsArtikelstamm.CancelEdit()
bsArtikelstamm.ResetBindings(False)
Else
IntelliSoft.myMessageBox.OfficeBox.Show("Folgender Fehler ist aufgetreten: " & _
ex.Message, LinqProvider.MessageCaption, _
MessageBoxButtons.OK, IntelliSoft.myMessageBox.OfficeMessageBoxIcon.Error)
End If
End Try
Finally
myDatacontext.Refresh()
Cursor.Current = saveCursor
End Try
The DataContext.Refresh() method should be called with RefreshMode specified, and a set of entities should be passed as parameter of this call.
I recommend you to specify the objects you want to be refreshed from database explicitly. Please let me know if anything goes wrong.
I recommend you to specify the objects you want to be refreshed from database explicitly. Please let me know if anything goes wrong.