Question

This is my code:

conn = new SqlConnection("Server=(localdb)\\v11.0;Integrated Security=true;AttachDbFileName=|DataDirectory|\\Users.mdf;MultipleActiveResultSets=True;");
conn.Open();

SqlCommand comm = new SqlCommand("update users set surname='simpson' where id=1", conn);
int i = comm.ExecuteNonQuery();
MessageBox.Show(i + "");

comm = new SqlCommand("select surname from users where id=1", conn);
SqlDataReader reader = comm.ExecuteReader();
if (reader.Read())
MessageBox.Show(reader[0] + "");
conn.Close();

The ExecuteNonQuery returns 1 to show the database has been updated and the second query confirms it. But when I open the database in visual studio 2013, there are no changes, database still the same

Was it helpful?

Solution

YOu mean, when you stop the program and Visual Studio throws away the copy of the database and resets it to the empty one then the data is gone? Yes, that is true.

OTHER TIPS

Maybe you need to change your connectionstring, or refresh the database.

Apparently the database had been set to copy to the output folder each time

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top