I'm pretty new to the EDM, so bear with me. I have a windows form that has a DataGridView on it that's bound from the EDM I created. I figured out how to update my changes fine, but it's when the user creates a new row that I'm having a problem.
I tried numerous ways and many google searches, but came up with nothing so far.
Here's how the data is loaded:
Dim boilerID As Integer = DirectCast(ddlBoiler.SelectedValue, Integer)
Dim countryID As Integer = DirectCast(ddlCountry.SelectedValue, Integer)
Dim ratings = From r In _Context.Rating _
Where r.Boiler.Boiler_ID = boilerID _
And r.Country.Country_ID = countryID _
Order By r.Sequence _
Select r
RatingBindingSource.DataSource = ratings.ToList()
Also, all I'm doing to save the information right now is the following:
Private Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click
_Context.SaveChanges()
End Sub
I want the user to be able to use the grid's "new row" feature to add new items to the database instead of having to click a button and open a new dialog. How would this be accomplished?
I can include some of the methods i tried for adding new items if anyone needs to see.
Thanks!
UPDATE: here's one of the methods I tried for adding new objects and the error I receive:
For Each dgvr As DataGridViewRow In dgvRatings.Rows
If dgvr.DataBoundItem IsNot Nothing AndAlso CType(dgvr.DataBoundItem, Rating).Rating_ID <= 0 Then
Dim r As Rating = dgvr.DataBoundItem
r.Boiler = ddlBoiler.SelectedItem
r.Country = ddlCountry.SelectedItem
_Context.AddObject("Rating", r)
End If
Next
Error (occurs when calling _Context.SaveChanges()): Store update, insert, or delete statement affected an unexpected number of rows (0). Entities may have been modified or deleted since entities were loaded. Refresh ObjectStateManager entries.