Click here to Skip to main content
15,904,934 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.

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

        MessageBox.Show("Changes saved to the database.")
    Catch ex As Exception
    End Try
End Sub

I am scratching my head all day. Don't know what I am doing wrong.

1 solution

I never use the designer to do any of my database work, ever. There's too much that goes on that you need to know about and understand how it works before using it and people just don't know anything about it. It's not really as simple as "drag, drop and you're done!".

But, you have a BindingSource (EmployeeBindingSource), but you don't mention what controls are being bound to it, such as a DataGridView, or whatever.

You can try adding EmployeeBindingSource.EndEdit() to just before you call context.SaveChanges().
Share this answer
adat7378 2-Apr-13 14:11pm    
Controls are textboxes. Even if I use datagrid the result is same. Is it the vb what makes it different. I mean the different way of doing the same work. I followed the c# below example.
Dave Kreskowiak 2-Apr-13 14:16pm    
The language does not matter. The .NET classes work exactly the same regardless of the language you're using.
adat7378 2-Apr-13 14:33pm    
Thanks Dave. At least it updates the records. But no luck for adding new record yet. I will appreciate any suggestion.
adat7378 2-Apr-13 14:35pm    
The MSDN example shows only savechanges method works. Am I missing something?
Dave Kreskowiak 2-Apr-13 15:09pm    
What do you mean by "adding"?? What exactly are you clicking on and doing before you click the Save button?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900