私はコードビハインドでこれを持っています:データベースに行を挿入すると挿入は正しいですが、ページを更新すると最後に挿入された行が何度も挿入されます。
protected void ButtonExecute_Click(object sender, EventArgs e)
{
string connectionString =cs.getConnection();
string insertSql = "INSERT INTO profitCategories(name, IdUser) VALUES(@name, @UserId)";
using (SqlConnection myConnection = new SqlConnection(connectionString))
{
myConnection.Open();
SqlCommand command = new SqlCommand(insertSql, myConnection);
command.Parameters.AddWithValue("@name", TextBoxCategory.Text);
command.Parameters.AddWithValue("@UserId", cui.getCurrentId());
command.ExecuteNonQuery();
myConnection.Close();
}
TextBoxCategory.Text = string.Empty;
}
これで問題が解決しました:ページを更新するたびに新しい行が挿入されました