Tag: formatexception

C#中的System.FormatException

我继续在我尝试为销售变量分配值的行中的每个案例中获得FormatException。 谁知道我做错了什么? 我应该把这个控制台程序作为学习循环的作业,但我发现了更多关于其他的东西。 它应该按照每次销售的10%佣金保持销售人员佣金的运行标签。 无论如何,这里是代码: using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace TubSales { class Program { static void Main(string[] args) { char initial; const double COMM_INT = 0.10; double sale, aComm = 0, bComm = 0, eComm = 0; Console.Write(“Enter ‘A’ for Andrea, ‘B’ for Brittany,\n’E’ for Eric, or ‘Z’ to quit […]

将DBNULL值解析为double

我使用以下行将datarow值转换为double。 double.parse(Convert.ToString(datarow)); 如果datarow是DBNULL ,我会收到以下exception: ‘double.Parse(Convert.ToString(data))’引发了‘System.FormatException’类型的exception 如何在不使用tryparse.情况下处理这个tryparse.

抛出格式exceptionC#

我试图在有人试图输入非整数字符的实例中抛出格式exception。 Console.WriteLine(“Your age:”); age = Int32.Parse(Console.ReadLine()); 我不熟悉C#语言,可以使用帮助为这个实例编写try catch块。 非常感谢。

为什么DateTime.Now.TimeOfDay.ToString(“HH:mm:ss.ffffff”)抛出FormatException?

抛出FormatException我遇到了类似的问题。 我的代码很简单: 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); } 这有什么不对? 这是一个线程问题吗?

System.FormatException:将字符串转换为十进制时,输入字符串的格式不正确。

我对ASP.NET和C#有点问题。 这是我的错误代码: mscorlib.dll中出现“System.FormatException”类型的exception,但未在>用户代码中处理 附加信息:输入字符串格式不正确。 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 oldAmount; bool succes = Decimal.TryParse(TextBox.Value, out oldAmount); if(succes) { ListItem item = Currency.Items[Currency.SelectedIndex]; decimal newAmount = oldAmount * […]

使用entity framework在运行时动态选择列

我有这样的现有function public int sFunc(string sCol , int iId) { string sSqlQuery = ” select ” + sCol + ” from TableName where ID = ” + iId ; // Executes query and returns value in column sCol } 该表有四列存储整数值,我使用上面的函数分别读取它们。 现在我将它转换为Entity Framework。 public int sFunc(string sCol , int iId) { return Convert.ToInt32(TableRepository.Entities.Where(x => x.ID == iId).Select(x […]

double.Parse抛出一个System.FormatException

我试图将一些字符串解析为double值,使用此解析方法重载: double.Parse(“198.222213745118”, CultureInfo.CurrentUICulture); CultureInfo.CurrentUICulture是fr-FR。 但这是抛出FormatException类型的exception。 可能是什么原因?

System.FormatException:输入字符串的格式不正确

private void ReadUnitPrice() { Console.Write(“Enter the unit gross price: “); unitPrice = double.Parse(Console.ReadLine()); } 这应该有用,但我遗漏了一些明显的东西。 每当我输入一个double时它就会给出错误:System.FormatException:输入字符串的格式不正确。 请注意,’unitPrice’被声明为double。

c#Convert.ToDouble格式exception错误

我正在尝试将此字符串转换为double Convert.ToDouble(“1.12”); 这是输出 System.FormatException未处理。 我应该这样做吗? 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”); 或者是否有更简单的解决方案?