微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

c# – 如何禁用按钮

如果检索的日期小于当前日期,我想停用button6,我已使用下面的代码,但它不起作用.请帮我找错.

protected void Button6_Click1(object sender,EventArgs e)
{
    MysqLConnection connection = new MysqLConnection("server=localhost; database=e-learningsystem; uid=root; password=123;port=3307;");
    connection.open();
    try
    {
        MysqLCommand cmd = new MysqLCommand("SELECT Date FROM fundamentals of is WHERE ChapNo=Chapter 1",connection);
        string date = Convert.ToString(cmd.ExecuteScalar());
        //date = cmd;
        if (Convert.ToDateTime(cmd).Compareto(System.DateTime.Now) < 0)
        {
            DownLoadFileFromServer("~/NewFolder1/" + "Fundamentals of IS.pdf");
        }
        else
        {
            Button6.Enabled = false;
        }
    }  
    catch (Exception ex)
    {
        // file IO errors

    }
}

这是serverMapPath代码

public static string ServerMapPath(string path)
{
    return HttpContext.Current.Server.MapPath(path);
}

public static HttpResponse GetHttpResponse()
{
    return HttpContext.Current.Response;
}
public static void DownLoadFileFromServer(string fileName)
{
    //This is used to get Project Location.
    try
    {
        string filePath = ServerMapPath(fileName);
        //This is used to get the current response.
        HttpResponse res = GetHttpResponse();
        res.Clear();
        res.AppendHeader("content-disposition","attachment; filename=" + filePath);
        res.ContentType = "application/octet-stream";
        res.WriteFile(filePath);
        res.Flush();
        res.End();
    }
    catch (Exception ex)
    {

    }
}

解决方法

MSDN答案:

我认为这会对你有所帮助

int result = DateTime.Compare(date1,date2);

string relationship;
if (result < 0)
   relationship = "is earlier than";
else if (result == 0)
   relationship = "is the same time as";         
else
   relationship = "is later than";

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐