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

有帮助吗?

解决方案

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.

其他提示

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top