Cannot save record using Entity Framework - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Cannot save record using Entity Framework

adat7378adat7378 Posts: 2Member
I am an absolute beginner. But I searched the net. There are not many example shown in VB anywhere.

I have created a test project which holds the win form. Then added another project which holds the Entity Model, after building the Model I added a reference of this to the Win form project. After that I added the Model object as a datasource.

I dragged the datasource controls into the form and added the below code.

Collapse | Copy Code
Private context As TestModelEntities

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

context = New TestModelEntities

Dim query = context.employees
EmployeeBindingSource.DataSource = query.ToList




End Sub

Private Sub DepartmentBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EmployeeBindingNavigatorSaveItem.Click



Try
context.SaveChanges()
MessageBox.Show("Changes saved to the database.")
Me.Refresh()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub

I am scratching my head all day. Don't know what I am doing wrong.
Sign In or Register to comment.