我有一個保存按鈕,它抓取信息並將它存儲在Winform的SQL中。 我遇到的問題是,如果您單擊保存按鈕,它仍將空白信息存儲在數據庫中。我不想要這個。這是我的代碼。請記住,實際的保存,更新和獲取數據是完美的。在C#Winfoms中停止按鈕點擊功能
private void btnSave_Click(object sender, EventArgs e)
{
if (txtLocalSourcePath.Text != null)
{
if (ResourceKey == 0)
{
ConnString = ConfigurationManager.ConnectionStrings["Dev"].ConnectionString;
GetData(ConnString);
InsertData(ConnString);
GetData(ConnString);
lblInsertNewRecord.Visible = true;
lblInsertNewRecord.Text = String.Format("You have inserted a new record at {0}", System.DateTime.Now);
}
else
{
UpdateData();
GetData(ConnString);
lblInsertNewRecord.Visible = true;
lblInsertNewRecord.Text = String.Format("Updated Record at {0}", System.DateTime.Now);
}
ClearData();
}
else
{
lblInsertNewRecord.Visible = true;
lblInsertNewRecord.Text = "Cannot add record. Please select file.";
}
}
我嘗試了這些選項: stopping a function executed on a winform button click How to cancel any event in winforms? How to cancel winform button click event?
您可能想嘗試'if(txtLocalSourcePath.Text!= null && txtLocalSourcePath.Text.Length> 0)'(編輯:固定'.Length'到'.Text.Length') –
好的,讓我試試看。感謝您的快速響應 –
我不能這樣做.Length是因爲它是DevExpress.XtraEditors.ButtonEdit –