我在代碼中插入背後: 當我向數據庫中插入一行時,它的插入是正確的,但是當我刷新頁面時,最後一次插入的行被一次又一次地插入。頁面刷新時每次插入記錄
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;
}
這解決了我的問題:New row inserted for each page refresh
看到這個link..http://stackoverflow.com/questions/1984090/new-row-inserted-for-each-page-refresh同樣的事情在這裏問。 .. – Pandian