0
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);
}

I want to add the new row of data (username, password) into the existing database but unfortunately it gets added temporarily only. As soon as the program is closed, the database is reverted to what it was.. Any help would be highly appreciated

John Saunders
  • 160,644
  • 26
  • 247
  • 397
  • you using sql express? check all database names in your server, you should have a database like `X:\\...\\user.sdf` and another database `user`, your first database going to be updated but not second. for checking it in sql server is easy but in express do `Select * from sys.databases` in `sqlcmd` window. – Saeed Amiri Nov 20 '10 at 20:54

1 Answers1

0

Have you seen this: Why isn't my SubmitChanges() working in LINQ-to-SQL?

Im assuming you're using Linq to Sql.
Linq to Entities would be: context.SaveChanges();

Community
  • 1
  • 1
gideon
  • 19,329
  • 11
  • 72
  • 113
  • what should i include in using for SaveChanges() ?? I tried that but it that does not get recognized :( – Kiran Timsina Nov 20 '10 at 09:34
  • btw, thanks for the link, i had googled it like crazy but maybe i was googling the wrong thing :P – Kiran Timsina Nov 20 '10 at 09:34
  • @Kiran yea sorry I made a mistake then changed my answer. You would use SaveChanges if you're using **Linq to Entities** (using Entity Framework). For **LinqtoSQL** use >> SubmitChanges(). Has your issue been resolved? – gideon Nov 20 '10 at 10:09
  • Seems like the main sdf file is always being copied to bin>debug folder and updated but my server explorer shows the table data of the main sdf which is always the same. I tried modifying the connection and it seems to help. I even changed the property of sdf file to "Copy if newer" and still experimenting with this. – Kiran Timsina Nov 20 '10 at 10:54