我是c#的新手。我试图使用以下代码从一种形式导航到另一种形式:
private void button2_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("server=xxxx-PC;database=node;uid=sa;pwd=xxxx;");
con.Open();
SqlCommand cmd = new SqlCommand("update nodes set filein='" + textBox1.Text + "' where id='" + textBox2.Text + "' ", con);
cmd.ExecuteNonQuery();
con.Close();
this.Hide();
Form2 form2 = new Form2();
form2.show();
}
但它隐藏了一个表单并抛出异常:
方法或操作未实施
答案 0 :(得分:0)
尝试此操作以查找错误的确切内容:
private void button2_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("server=xxxx-PC;database=node;uid=sa;pwd=xxxx;");
SqlCommand cmd = new SqlCommand("update nodes set filein='" + textBox1.Text + "' where id='" + textBox2.Text + "' ", con);
try
{
con.Open();
cmd.ExecuteNonQuery();
this.Hide();
Form2 form2 = new Form2();
//error here
//form2.show();
//replace this with
form2.Show();
}
catch (Exception ex)
{
throw ex;
}
finally
{
con.Close();
}
}