Quantcast
Channel: ASP.NET AJAX + Ajax Control Toolkit (ACT)
Viewing all articles
Browse latest Browse all 5678

String was not recognized as a valid DateTime.

$
0
0

I'm using ajaxcalendarextender to select date with time. The format of the date is: 08/01/2018 12:00:00

After select date, click search, error come out: 

String was not recognized as a valid DateTime.

The error only display when running on server. If I running on localhost no problem. Not sure calendarexterder problem or what else.

Here is the code:

<asp:TextBox ID="tbFromDate" runat="server"></asp:TextBox><asp:CalendarExtender ID="tbFromDate_CalendarExtender" runat="server" 
        TargetControlID="tbFromDate" Format="MM/dd/yyyy hh':'mm':'ss"></asp:CalendarExtender>
<asp:TextBox ID="tbToDate" runat="server"></asp:TextBox><asp:CalendarExtender ID="tbToDate_CalendarExtender" runat="server" 
        TargetControlID="tbToDate" Format="MM/dd/yyyy hh':'mm':'ss"></asp:CalendarExtender>
        private void getData()
        {
            string connStr = ConfigurationManager.ConnectionStrings["STSConn"].ConnectionString;
            string sdt = string.Format("{0:MM/dd/yyyy}", tbFromDate.Text);
            string edt = string.Format("{0:MM/dd/yyyy}", tbToDate.Text);

            string query = string.Format(sql, this.getCheckBoxList(), this.getCheckBoxList2(), this.getCheckBoxList3());
            DataTable table = new DataTable();
            using (SqlConnection conn = new SqlConnection(connStr))
            {
                // instantiate the command object to fire            
                using (SqlCommand cmd = new SqlCommand(query, conn))
                {
                    cmd.CommandType = CommandType.Text;
                    cmd.Parameters.AddWithValue("@sdate", sdt);
                    cmd.Parameters.AddWithValue("@edate", edt);
                    //cmd.Parameters.AddWithValue("@line", line);

                    // get the adapter object and attach the command object to it                
                    using (SqlDataAdapter ad = new SqlDataAdapter(cmd))
                    {
                        // fire Fill method to fetch the data and fill into DataTable                    
                        ad.Fill(table);
                    }
                }
            }

            ViewState["table"] = table;
            GridView1.DataSource = table;
            GridView1.DataBind();

            this.getOverallChart(table);
        }


Viewing all articles
Browse latest Browse all 5678

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>