I'm using a Service-based Database (.MDF) to save some data from an application I'm developing. However, after I close the application, the data that was entered in the table disappears. Here is the code I'm using:
System.Data.SqlClient.SqlConnection sqlConnection1 =
new System.Data.SqlClient.SqlConnection(@"Data Source=(LocalDB)\v11.0;Integrated Security=True;AttachDbFilename=|datadirectory|\Database2.mdf");
System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand();
cmd.CommandType = System.Data.CommandType.Text;
sqlConnection1.Open();
cmd.CommandText = @"INSERT INTO sistemas (nome, potnom, numcolun, colunpac, colunpcc, colunirrad, tempomed) VALUES ('"+ nome+ "','"+ potNom+"','"+ numcolun +"','"+ colunpac+"','" + colunpcc + "','" +colunirrad+"','" + tempoMed + "')";
cmd.Connection = sqlConnection1;
cmd.ExecuteNonQuery();
sqlConnection1.Close();
The INSERT is executed correctly, I can query the database if I do not close the application, however, when I restart the application, the table returns empty.