I have made a datagridview with data from database, then I have 3 different forms with insert data, delete data, etc.
The problem is that when I'm trying to insert data and restart the program, the data doesn't get saved.
Here is my code:
SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database1.mdf;Integrated Security=True;User Instance=True");
con.Open();
string sql = "INSERT INTO Elevi (Nume, Prenume, SportulPracticat) VALUES(@nume, @prenume, @sport)";
using (SqlCommand cmd = new SqlCommand(sql, con))
{
cmd.Parameters.AddWithValue("@nume", textBox1.Text);
cmd.Parameters.AddWithValue("@prenume", textBox2.Text);
cmd.Parameters.AddWithValue("@sport", textBox3.Text);
cmd.ExecuteNonQuery();
}
con.Close();