formatexception

Dynamically select columns in runtime using entity framework

守給你的承諾、 提交于 2019-11-27 06:54:40
问题 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 )

c# Convert.ToDouble format exception error

风格不统一 提交于 2019-11-26 22:02: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? 回答1:

Input string was not in a correct format

北慕城南 提交于 2019-11-25 23:01:38
问题 I\'m new with C#, I have some basic knowledge in Java but I can\'t get this code to run properly. It\'s just a basic calculator, but when I run the program VS2008 gives me this error: I did almost the same program but in java using JSwing and it worked perfectly. Here\'s the form of c#: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace calculadorac {