??????? private void btnDelete_Click(object sender, EventArgs e)??????? {??????????? //只能顯示??????????? string sql = "delete from T_Cost where HasConfirm=0 ";??????????? //如果datagridview的當前行被選中??????????? if (dgvEntry.CurrentRow.Selected)??????????? {??????????????? //將sql語句 delete from T_Cost where HasConfirm=0 and CostId =(CostId號)??????????????? sql = sql + "and CostcostIDDataGridViewTextBoxColumn"].Value.ToString());??????????? }??????????? int n = 0;??????????? SqlConnection conn = new SqlConnection(connStr);??????????? SqlCommand cmd = new SqlCommand(sql, conn);??????????? conn.Open();??????????? n = cmd.ExecuteNonQuery();??????????? conn.Close();??????????? if (n > 0)??????????? {??????????????? MessageBox.Show("刪除成功!");??????????? }??????????? else??????????? {??????????????? MessageBox.Show("不存在的ID!");??????????? }??????????? //刪除完后 刷新一下當前數(shù)據(jù)??????????? Refresh();??????? }
例如上邊的這個 刪除成功以后調用refresh方法 datagridview中的數(shù)據(jù)不能更新 而且有時候插入數(shù)據(jù)的時候數(shù)據(jù)庫中的數(shù)據(jù)也不更新 但是下次再運行程序的時候數(shù)據(jù)已經(jīng)插入或者刪除了 是這個刷新的方法有問題還是數(shù)據(jù)庫有緩存啊 我是在本地VS上建的數(shù)據(jù)庫做測試用 會不會有影響啊 哪位大哥幫忙看一下哪的代碼有問題 還是別的問題 這是我做的第一個程序啊 謝謝各位了
winform程序Datagridview和數(shù)據(jù)庫不能達到與操作的同步
慕無忌1623718
2018-12-07 00:47:18