[英]I need to reload the form on button click
I have been trying different methods these past days to overcome this problem but I haven't found a reliable solution to my problem. 过去几天,我一直在尝试其他方法来克服此问题,但是我没有找到可靠的解决方案。 The problem is I have to reload the form in case the first time the application starts and the components are not filled up due to network or SQL connectivity issue.
问题是我必须重新加载表单,以防应用程序首次启动并且由于网络或SQL连接问题而导致组件未满的情况。 As of now, everyone is closing the application and starting again because the first time they start the application the components were empty.
到目前为止,每个人都在关闭应用程序并重新启动,因为他们第一次启动应用程序时组件为空。
Below is the code I'm using. 下面是我正在使用的代码。
private void Reports_Load(object sender, EventArgs e)
{
//START:
try
{
RevenueDate_dt = func.getResult(dateQuery);
foreach (DataRow dr in RevenueDate_dt.Rows)
{
comboBox1.Items.Add(dr["Global_Period_Month"].ToString());
}
}
catch (Exception ex)
{
//goto START;
MessageBox.Show("Network is too slow! Please close the application and try again later");
}
}
Function: 功能:
public DataTable getResult(string query)
{
//con.Open();
SqlDataAdapter da = new SqlDataAdapter();
DataTable dt = new DataTable();
SqlCommand cmd = new SqlCommand(query, con);
cmd.CommandTimeout = 0;
da.SelectCommand = cmd;
da.Fill(dt);
return dt;
}
I have placed a retry button on my form so if the first time the component is not filled with the data so everyone can use the retry button to load the component instead of closing the whole application and starting again. 我在表单上放置了一个重试按钮,因此,如果第一次在组件中未填充数据,那么每个人都可以使用重试按钮加载该组件,而不必关闭整个应用程序并重新启动。
You can fill component by calling Reports_Load
event
in your retry button
. 您可以通过在
retry button
调用Reports_Load
event
来填充组件。 Reports_Load
will fill your component. Reports_Load
将填充您的组件。 Check below code. 检查以下代码。
CODE: 码:
private void retry_Click(object sender, EventArgs e)
{
Reports_Load(null, null);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.