我有一个网页表单有2个按钮显示和取消。在显示按钮点击事件我显示取消按钮并执行查询,如果查询需要很长时间。我想从取消按钮取消该查询。我搜索了很多,sqlcommand .cancel()方法可能需要使用。如何使用,因为在button1中写这样的
Button1_click()
{
String connectionString = WebConfigurationManager.ConnectionStrings["sampleConnectionString"].ConnectionString;
String sqlselect = "select * from Table";
SqlConnection con = new SqlConnection(connectionString);
try
{
con.Open();
SqlCommand cmd = new SqlCommand(sqlselect, con);
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
}
catch (Exception ex)
{
ex.ToString();
}
finally
{
con.Close();
}
}