Home > Net >  Rookie help System. InvalidCastException: "transformation of specified is invalid."
Rookie help System. InvalidCastException: "transformation of specified is invalid."

Time:10-06

Public static List GetBianwenlist DataTable (dt)
{
List Lists=null;
If (dt. Rows. Count & gt; 0)
{
Lists=new List (a);
//traverse table each row record
Foreach (DataRow row in dt. Rows)
{
//each line corresponds to a data object
Bianwen temp=new bianwen ();
Temp. Materials=row [" Materials "). The ToString ();
if (! (row [" Condiction "] is DBNull | | string. IsNullOrEmpty (row [" Condiction "]. ToString ())))
{
Temp. Condiction=row [" Condiction "]. ToString ();
}
Temp. Mocaxishu=(int) row [" Mocaxishu "];
Temp. Mosunliang=(int) row [" Mosunliang "];
//add objects to the collection
Lists. The Add (temp);
}
}
Return lists.
}
}
}
Temp. Mocaxishu=(int) row [" Mocaxishu "]; Exception: System. InvalidCastException: "the specified transformation is invalid,"
For help

CodePudding user response:

Mosunliang you this is a list of type int, you to look at the column of data

CodePudding user response:

Is the decimal, but is I use float

CodePudding user response:

reference 1/f, 711 glaciers response:
Mosunliang you this is a list of type int, you to look at your data the column of
is decimal, but with a float

CodePudding user response:

Double. Parse (row [" Mocaxishu "]. ToString ())
Null values, in his own judgement

CodePudding user response:

In decimal, who know how big the number to reach you, there is nothing wrong with using decimal
  • Related