如果检索到的日期小于当前日期,我想停用 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)
{
}
}