![](/img/trans.png)
[英]login function in a visual studio C# windows form connected to a MS Access database 2000 - 2003 format. Researched and tried fixing to no avail
[英]Error fixing my MS Access Database in Visual C#
我一直在使用 windows forms 創建一個分配項目,基本上我的程序包括 3 個 forms:登錄、數據庫查看器和一個單獨的表單來編輯數據庫。
編輯數據庫時:如果數據庫為空,並且我嘗試刪除一條記錄兩次我的程序中斷,我收到錯誤: System.InvalidOperationException: 'Current item cannot be removed from the list because there is no current item.'
是否有任何類型的代碼可以實現以防止在表為空時使用刪除按鈕?
這是我的數據庫刪除按鈕的代碼,實際上沒有任何其他代碼與我自己更改的數據庫有關,因為我不知道該怎么做。
private void bindingNavigatorDeleteItem_Click(object sender, EventArgs e)
{
if (MessageBox.Show("Are you sure you'd like to delete this record?", "Delete Record", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
this.computer_GamesBindingSource.RemoveCurrent();
this.Validate();
this.computer_GamesBindingSource.EndEdit();
}
}
嘗試做這樣的檢查:
if (this.computer_GamesBindingSource.Count > 0)
{
/* put delete code here */
}
這樣刪除代碼只有在有記錄時才會執行。
有關詳細信息,請參閱https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.bindingsource.count
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.