Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/328.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 每当执行查询时,在asp.net中显示该按钮_C#_Asp.net_Sql Server - Fatal编程技术网

C# 每当执行查询时,在asp.net中显示该按钮

C# 每当执行查询时,在asp.net中显示该按钮,c#,asp.net,sql-server,C#,Asp.net,Sql Server,我将asp.net与c一起使用,我的aspx代码如下所示 <html xmlns="http://www.w3.org/1999/xhtml"> <body> <asp:Panel ID="panel1" runat="server"> <table><tr><td><asp:Label ID="Label2" runat="server" Font-Bold="True" Font-Underli

我将asp.net与c一起使用,我的aspx代码如下所示

<html xmlns="http://www.w3.org/1999/xhtml">
<body>

<asp:Panel ID="panel1" runat="server">
<table><tr><td><asp:Label ID="Label2" runat="server" Font-Bold="True" 
        Font-Underline="True"></asp:Label></td></tr>

 <tr> <td>
   <asp:Button ID="btnsubmit" runat="server" Text="Submit" BackColor="#993300" 
       ForeColor="White" onclick="btnsubmit_Click" /></td>
<td>
    <asp:Button ID="btnlogout" runat="server" Text="Logout" BackColor="#993300" 
       ForeColor="White" onclick="btnlogout_Click"  />
</td>
</tr>
</table>
它出现在submit按钮中,每当上述查询为真并执行时,我需要显示submit按钮,否则我不需要显示submit按钮

 protected void btnsubmit_Click(object sender, EventArgs e)
{
    string type = "c";
    string FID = Session["FID"].ToString();
    SqlConnection cn = new SqlConnection();
    SqlCommand cmd = new SqlCommand();
    //int str_diff = Convert.ToInt32(ConfigurationManager.AppSettings["Difference"]);
    cn.ConnectionString = @"Data Source=BOPSERVER;Initial Catalog=Project;Integrated Security=True";
    cn.Open();
    cmd.CommandText = *"update TrackingFaculty_det SET Type=@Type WHERE (FID=@FID) and DATEDIFF(d,TrackingFaculty_det.LastUpdateDate,GETDATE())>60*";
    cmd.Connection = cn;
    cmd.Parameters.Add("@FID",SqlDbType.VarChar,10);
    cmd.Parameters["@FID"].Value = FID;
    cmd.Parameters.Add("@Type", SqlDbType.VarChar, 1);
    cmd.Parameters["@Type"].Value = type;
    cmd.ExecuteNonQuery();
    cn.Close();

    Response.Redirect("~/Faculty/Personaldet.aspx");
}
protected void btnlogout_Click(object sender, EventArgs e)
{
    Response.Redirect(@"~\home.aspx");
}

仅当执行update TrackingFaculty_det SET Type=@Type,其中FID=@FID和DATEDIFFd,TrackingFaculty_det.LastUpdateDate,GETDATE>60时,此图像才应显示。将提交按钮进程置于表单加载事件上,然后添加一个条件(如果为真),然后隐藏/禁用btnsubmit

您正在对同一按钮触发查询这是不可行的,您需要像这样启动select查询

在类似页面加载的情况下,它返回true/false,获取结果,现在取决于结果集按钮属性

Button1.Enabled = false; // make button as disable
Button1.Visible = false; // make button invisible

你想隐藏/显示-启用/禁用你的提交按钮取决于你的查询结果@Satindersingh我需要在执行查询时显示它们,仅供参考,从现在起,查询将每两个月执行一次。你在同一个按钮上启动查询这是不可行的,你需要在页面上启动查询,例如页面加载,获取结果并依赖结果集按钮属性enable=false/trueLook for@Satinder sing answer只需将其放入页面加载事件中即可
Select * from TrackingFaculty_det  where  FID=@FID and 
DATEDIFF(d,TrackingFaculty_det.LastUpdateDate,GETDATE())>60
Button1.Enabled = false; // make button as disable
Button1.Visible = false; // make button invisible