I have a small problem here. When I tried to do the following steps,
string set1="123.10,134.40";
string set2="17,134";
List<string> List1 = new List<string>(set1.Split(','));
List<string> List2 = new List<string>(set2.Split(','));
var QueryResult = from D1 in List1
from E1 in List2
select new
{
D1,
E1
};
DataTable tempDT = new DataTable();
tempDT.Columns.Add("Data1", typeof(int));
tempDT.Columns.Add("Data2", typeof(string));
foreach (var item in QueryResult)
{
tempDT.Rows.Add(new object[] {Convert.ToInt32(item.E1.ToString()),
Convert.ToString(item.D1.ToString()) });
}
When I try to add those values to the tempDT I am getting an exception:
Input string was not in a correct format.
How do I fix this issue?
It is because you are using Convert.ToInt32 on a string that contains a decimal character.