我有一个保存按钮,它抓取信息并将它存储在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 –