DateTime Format issue in IIS 7 Server

Last Reply on Mar 15, 2017 02:23 AM By itsjayshah

Posted on Mar 15, 2017 02:04 AM

it is working well in while developing the website but once i deploy in IIS i am getting the error like 

"string was not recognized as a valid datetime"

Front End:

<div class="form-group">
    <div class="row">
        <label class="col-md-3 control-label">
            From Date:
        </label>
        <div class="col-md-9">
            <div class="input-group">
                <asp:TextBox ID="txtndate" runat="server" class="form-control" MaxLength="15" Style="width: 75%;
                    margin-right: 5px; color: #000;"></asp:TextBox>
                <asp:ImageButton ID="imgPopup" ImageUrl="img/calendar.png" runat="server" Style="margin-top: 5px;" />
                <asp:CalendarExtender ID="Calendar1" PopupButtonID="imgPopup" runat="server" TargetControlID="txtndate"
                    Format="dd/MM/yyyy">
                </asp:CalendarExtender>
                <asp:CalendarExtender ID="CalendarExtender2" PopupButtonID="txtndate" runat="server"
                    TargetControlID="txtndate" Format="dd/MM/yyyy">
                </asp:CalendarExtender>
            </div>
        </div>
    </div>
</div>
<div class="form-group">
    <div class="row">
        <label class="col-md-3 control-label">
            To Date:
        </label>
        <div class="col-md-9">
            <div class="input-group">
                <asp:TextBox ID="txtntdate" runat="server" class="form-control" MaxLength="15" Style="width: 75%;
                    margin-right: 5px; color: #000;"></asp:TextBox>
                <asp:ImageButton ID="imgPopup2" ImageUrl="img/calendar.png" runat="server" Style="margin-top: 5px;" />
                <asp:CalendarExtender ID="CalendarExtender3" PopupButtonID="imgPopup2" runat="server"
                    TargetControlID="txtntdate" Format="dd/MM/yyyy">
                </asp:CalendarExtender>
                <asp:CalendarExtender ID="CalendarExtender4" PopupButtonID="txtntdate" runat="server"
                    TargetControlID="txtntdate" Format="dd/MM/yyyy">
                </asp:CalendarExtender>
            </div>
        </div>
    </div>
</div>

Back END:

//  SqlCommand cmd = new SqlCommand("insert into newsevents values(@newsevents_title, @newsevents_describe, @newsevents_img, @newsevents_date, @newsevents_todate, @active,@registereddate,@registeredby,@modifieddate,@modifiedby);", cn);
SqlCommand cmd = new SqlCommand("employee_pro", cn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@status", "Add");
cmd.Parameters.Add("@newsevents_title", txtfeaturename.Text);
cmd.Parameters.Add("@newsevents_describe", CKEditor1.Text);
cmd.Parameters.Add("@newsevents_img", imgname);
cmd.Parameters.Add("@newsevents_date", DateTime.ParseExact(txtndate.Text, "dd/MM/yyyy", CultureInfo.InvariantCulture));
cmd.Parameters.Add("@newsevents_todate", DateTime.ParseExact(txtntdate.Text, "dd/MM/yyyy", CultureInfo.InvariantCulture));
cmd.Parameters.Add("@active", "Y");
cmd.Parameters.Add("@registereddate", System.DateTime.Now);
cmd.Parameters.Add("@registeredby", Convert.ToInt32(Session["admin_id"].ToString()));
cmd.Parameters.Add("@modifieddate", System.DateTime.Now);
cmd.Parameters.Add("@modifiedby", Convert.ToInt32(Session["admin_id"].ToString()));
cmd.ExecuteNonQuery();
You are viewing reply posted by: itsjayshah on Mar 15, 2017 02:23 AM.
Posted on Mar 15, 2017 02:23 AM

I got the Answer

<system.web>
    <globalization culture="en-GB" uiCulture="en-GB" />
    ....
</system.web>