my problem is currently that I add a player to the database and that player is visible only as long as the program runs.
The test() method should add a player to the database.
private static void Test()
{
SqlConnection connection;
string connectionString = ConfigurationManager.ConnectionStrings["Footbal.Properties.Settings.cn"].ConnectionString;
connection = new SqlConnection(connectionString);
connection.Open();
string query = "INSERT INTO Players(id, player_name, player_price, player_rating) VALUES(@id, @player_name, @player_price, @player_rating)";
string name = "Ronaldo";
SqlCommand testInsert = new SqlCommand(query, connection);
testInsert.Parameters.AddWithValue("@id", 43);
testInsert.Parameters.AddWithValue("@player_name", name);
testInsert.Parameters.AddWithValue("@player_price", 34);
testInsert.Parameters.AddWithValue("@player_rating", 54);
testInsert.ExecuteScalar();
connection.Close();
}
After this method the DataGridView is filled. (playersTableAdapter acts as a bridge between DataSet(db_PlayersDataSet.Players) and database)
playersTableAdapter.Fill(db_PlayersDataSet.Players);
So far everything works as expected. And now when I close the program, the added data is gone.
What is the problem?