简体   繁体   中英

String was not recognized as a valid DateTime

My code is .......

  string PName = Request.QueryString["ProductName"] as string;
  string myDate = Request.QueryString["period"];

 string sql = "select FileName from tblProduct Where ProductName=" + PName;



    DateTime dt1 = Convert.ToDateTime(myDate);
    DateTime dt2 = DateTime.Now;
    TimeSpan variable = dt2 - dt1;
    if (variable.TotalMinutes > 5)
    {
        //Response.Write("Download time is expired now");
        lblmsg.Visible = true;
        lblmsg.Text = "Download time is expired now";
    }
    else
    {
        //string url1 = " http://www.shreehans.co.in/files/" + PName +"";
        //Response .Redirect ()
        lblmsg.Visible = true;
        lblmsg.Text = "U can Still Download";
    }

And My URl is with querystring parameters ......

mail.Body += string.Format("http://www.abc.co.in/Download.aspx?period=" + DateTime.Now + "&ProductName=" + productName + "\\">Demo Download");

如果在url(查询字符串)中包含日期,则应将其编码为Server.UrlEncode(DateTime.Now)

In addition:

  1. You're missing a \\" when constructing the URI.
  2. Your SQL code is susceptible to SQL injection attack.

This will resolve your problem

mail.Body += 
   string.Format("http://www.abc.co.in/Download.aspx?period=" + 
   DateTime.Now.ToString("dd-MMM-yyyy") + 
   "&ProductName=" + productName + "\">Demo Download"); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM