如何在數據網格視圖中立即顯示數據插入或更新。我要重新啓動該項目表明,Data.I使用更新()和刷新()但不是爲我工作如何在插入或更新後更新DataGridview
private void UpdateDebtbutton_Click(object sender, EventArgs e) { SqlConnection conn = ForConnection(); conn.Open(); using (conn) { if (paytextBox.Text != "") { SqlCommand cmd = new SqlCommand("spdebth", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@id", SqlDbType.Int).Value =customerIDTextBox.Text.ToString(); cmd.Parameters.Add("@text", SqlDbType.Int).Value = paytextBox.Text.ToString(); cmd.ExecuteNonQuery(); MessageBox.Show("Record updated"); spSelectAllCustomerDataGridView.Update(); spSelectAllCustomerDataGridView.Refresh(); conn.Close(); } } }
再次設置數據源。 – Berkay
@Berkay謝謝你親愛的現在工作 –
使用DatatGridView的DataTable你嘗試過dataTable.AcceptChanges(); – JohnG