Context.SaveChanges() is not working

1.8k Views Asked by At

The following is my code. When I see table data after executing of this code, it still is blank. Any ideas to make the following code work would be appreciated.

Dim dbcontext As New Model1Container

    Dim employee As New emp
    employee.empid = 1
    employee.empname = "some name"
    employee.empaddress = "some address"
    dbcontext.emps.AddObject(employee)

    Try
        dbcontext.SaveChanges()
    Catch ex As Exception
        MsgBox(ex.Message)
    End Try

I am using VS 2010 Professional Edition and SQL Server 2008 Express Edition.

2

There are 2 best solutions below

3
On

Didyou try with dbcontext.SubmitChanges()

Reference - 1

Reference - 2

0
On

Are you using a local database file? You may be looking for changes in the wrong place. By default, when the program starts, VS copies the database file into the debug or release folder. Then the program runs and changes are made, and saved, to the file in the debug or release folder. The program ends, and when you look at the database in your source folder it looks the same. You can change the connection string in the app.config to use an absolute path to avoid this.

See http://blogs.msdn.com/b/smartclientdata/archive/2005/08/26/456886.aspx for more info