formatexception

DateTime.Parse throwing format exception

走远了吗. 提交于 2019-12-01 17:48:27
问题 I retrieve date and time strings from xml by parsing XElement. The date and time values are retrieved by file.Element("Date").Value and file.Element("Time").Value respectively. After I retrieve the Date value I parse it to a DateTime variable DateTime dt,ts; dt = file.Element("Date").Value; // the value is say 12/29/2012 and then this dt value is set to a datepicker value on the xaml UI datepicker.Value = dt; I also have a timepicker whose value have to be set by the Time value retrieved from

Why does DateTime.Now.TimeOfDay.ToString(“HH:mm:ss.ffffff”) throw FormatException?

夙愿已清 提交于 2019-12-01 02:41:44
I'm having a similar problem with FormatException being thrown. My code is simply: void Orders_OnSubmit() { DateTime CurrentTime = DateTime.Now; rtbAdd( "Submitted on " + CurrentTime.Date.ToString("MM/dd/yyyy") + " at " + CurrentTime.TimeOfDay.ToString("HH:mm:ss.ffffff") ); } void rtbAdd(String S) { DefaultDelegate del = delegate() { rtb.AppendText(S + "\n"); }; this.Invoke(del); } What's wrong here? Is this a threading issue? There's no need to explicitly access the Date and TimeOfDay properties of the DateTime instance. You can simplify your code like so: rtbAdd(String.Format("Submitted on

System.FormatException : Input string was not in a correct format ,on converting string to decimal.

北战南征 提交于 2019-11-30 20:24:54
I have a little problem with ASP.NET and C#. This is my error code: An exception of type 'System.FormatException' occurred in mscorlib.dll but was not handled in >user code Additional information: Input string was not in a correct format. protected void Page_Load(object sender, EventArgs e) { if(this.IsPostBack == false) { Currency.Items.Add(new ListItem("Euro", "0.85")); Currency.Items.Add(new ListItem("Yen", "11.30")); Currency.Items.Add(new ListItem("PLN", "4.20")); Currency.Items.Add(new ListItem("GBP", "5.62")); } } protected void Convert_Click(object sender, EventArgs e) { decimal

Why am I getting a FormatException was unhandled error?

…衆ロ難τιáo~ 提交于 2019-11-28 14:11:47
I have created a program, and a extensive test of it, I'm getting a error that says "FormatException was unhandled, Input string was not in a correct format". The problem occurs when I leave either of the text boxes blank and press the 'Finished' button but it works fine if I enter anything below 0 or above 59 - which is the number range I want to allow. What could I do so I don't receive this error when the boxes are blank? This is my code behind 'btnFinished': private void btnFinished_Click(object sender, EventArgs e) { if (lstCyclists.SelectedIndex >= 0) { Cyclists currentCyc = (Cyclists

System.FormatException: Input string was not in a correct format

僤鯓⒐⒋嵵緔 提交于 2019-11-28 12:28:16
private void ReadUnitPrice() { Console.Write("Enter the unit gross price: "); unitPrice = double.Parse(Console.ReadLine()); } This should work, but I'm missing something obvious. Whenever I input a double it gives me the error: System.FormatException: Input string was not in a correct format. Note that 'unitPrice' is declared as a double. It could be that you're using wrong comma separation symbol or even made an other error whilst specifying double value. Anyway in such cases you must use Double.TryParse() method which is safe in terms of exception and allows specify format provider,

Dynamically select columns in runtime using entity framework

允我心安 提交于 2019-11-28 12:14:55
I have an existing function like this public int sFunc(string sCol , int iId) { string sSqlQuery = " select " + sCol + " from TableName where ID = " + iId ; // Executes query and returns value in column sCol } The table has four columns to store integer values and I am reading them separately using above function. Now I am converting it to Entity Framework . public int sFunc(string sCol , int iId) { return Convert.ToInt32(TableRepository.Entities.Where(x => x.ID == iId).Select(x => sCol ).FirstOrDefault()); } but the above function returns an error input string not in correct format because it

c# Convert.ToDouble format exception error

孤者浪人 提交于 2019-11-28 01:56:45
I'm trying to convert this string to double Convert.ToDouble("1.12"); and this is the output System.FormatException was unhandled. Should I do something like this? public static double ConvertToDouble(string ParseVersion) { double NewestVersion; try { NewestVersion = Convert.ToDouble(ParseVersion); } catch { ParseVersion = ParseVersion.Replace('.', ','); NewestVersion = Convert.ToDouble(ParseVersion); } return NewestVersion; } ConvertToDouble("1.12"); Or is there an easier solution? double.Parse will use the current culture by default. It sounds like you want the invariant culture: double d =

Why am I getting a FormatException was unhandled error?

喜你入骨 提交于 2019-11-27 08:23:36
问题 I have created a program, and a extensive test of it, I'm getting a error that says "FormatException was unhandled, Input string was not in a correct format". The problem occurs when I leave either of the text boxes blank and press the 'Finished' button but it works fine if I enter anything below 0 or above 59 - which is the number range I want to allow. What could I do so I don't receive this error when the boxes are blank? This is my code behind 'btnFinished': private void btnFinished_Click

double.Parse throw a System.FormatException

南笙酒味 提交于 2019-11-27 08:05:48
问题 I am trying to parse some string to a double value, using this parse method overload: double.Parse("198.222213745118", CultureInfo.CurrentUICulture); the CultureInfo.CurrentUICulture is fr-FR. but this is throwing an exception of type FormatException. What can be the reason? 回答1: French (i.e. fr-FR ) use a comma to denote the start of the decimal part, not a period. They use a period to separate thousands. 回答2: I know this question is old but my answer might help someone else. So this is the

System.FormatException: Input string was not in a correct format

痴心易碎 提交于 2019-11-27 07:05:00
问题 private void ReadUnitPrice() { Console.Write("Enter the unit gross price: "); unitPrice = double.Parse(Console.ReadLine()); } This should work, but I'm missing something obvious. Whenever I input a double it gives me the error: System.FormatException: Input string was not in a correct format. Note that 'unitPrice' is declared as a double. 回答1: It could be that you're using wrong comma separation symbol or even made an other error whilst specifying double value. Anyway in such cases you must