本地数据库在构建后丢失更改

时间:2010-11-20 09:15:19

标签: c# linq-to-sql

string connectionString =
     "Data Source =|DataDirectory|\\user.sdf";
User context = new User(connectionString);

Userdetail newUser = new Userdetail();


newUser.Username = txtReg.Text;
newUser.Password = txtRegPassword1.Password;
try
{
    context.Userdetail.InsertOnSubmit(newUser);

    context.SubmitChanges();


}
catch (ChangeConflictException)
{
  context.ChangeConflicts.ResolveAll(System.Data.Linq.RefreshMode.KeepChanges);
}

我想将新的数据行(用户名,密码)添加到现有数据库中,但遗憾的是它只是暂时添加。一旦程序关闭,数据库就会恢复原状。任何帮助都将受到高度赞赏

1 个答案:

答案 0 :(得分:0)

你见过这个: Why isn't my SubmitChanges() working in LINQ-to-SQL?

我假设你正在使用Linq到Sql Linq to Entities将是:context.SaveChanges();