.NET General

Moderators: None (Apply to moderate this forum)
Number of threads: 797
Number of posts: 1359

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Cannot save record using Entity Framework Posted by adat7378 on 5 Apr 2013 at 5:44 AM
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.



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.