c# - datetime working locally but not on server -
I have a form that includes a date ..
Working locally , When I submit it to the form works terribly and saves the date of the server.
But when I try to do this with the server, I get an error:
string valid date time. System Collections.LivisionInNellal
Code:
Using the system; Using System.Collections.Generic; Using System.Linq; Using System.Web; Using System.Web.UI; Using System.Web.UI.WebControls; Using System.Globalization; Public Partial Classroom Test: System.Web.UI.Page {Secure Zero dog_add_submit_Click (Object Sender, EventArgs) • Create and Populate Dog / Dog D = New Dog (); Try {d.DogName = dog_add_name.Text; D.IgeErl = SaveSize (); D.Colour = dog_add_colour.Text; D.PlaceFrom = dog_add_placeFrom.Text; D.Breed = dog_add_breed.Text; D.ArrivalDate = DateTime.Parse (txtDate.Text); // If the fields are properly populated then try to insert C # into the database {int numEffected = d.doginsert (); // Response.Write ("Points of Effective Rows" are + numEffected.ToString ()); Response.Redirect ("MedicalHistoryAdd.aspx? Dogid =" + d.SqldogID); } Hold (Exceptional Before) {Response.Write ("There was an error while trying to insert the dog into the database". }} Hold (Exception Pre) {Response.Write (ex.Message + ex.Data); }}}}
.NET sets your machine as default on whatever default It's going to be running. This means that it will parse datetime and toasting () datetime in that locale. So my guess is if your local language / timezone preferences are different from the server?
You make them web. You can set certain expectations in the config and output:
& Lt; /system.web>
My Danish is, you may want N-GB or N-US?
The second option is to shoot fish in a barrel with an irreversible format provider.
> DateTime Purse (txtDate.Text, DateTimeFormatInfo.InvariantInfo);
Hope that helps!
Comments
Post a Comment