1
I’m trying to pass the data from a file. csv to a datatable and the code seems to be all ok but I’ve been back from this error for quite some time and don’t know how to fix it.
I have two columns in my . csv file and a string type another integer type and the error from what I realized is giving in the first line in which the "ATID" is not entire in this first line being that the rest is a whole number and I do not know how to solve thanks help. I tried to make conversions and it didn’t work (I may have done wrong, some help is welcome).
Example:
PPID ; ATID
Asd ; 1
Asd ; 2
Asd ; 3
dsa ; 4
Erf ; 5
Error: System.Argumentexception: 'Input string was not in a correct format. Couldn’t store <#assetId#> in Atid Column. Expected type is Int32.'
Code:
using (StreamReader sr = new
StreamReader(@"C:Pathfile....csv"))
{
var datatable = new DataTable();
datatable.Columns.Add("PPId", typeof(string));
datatable.Columns.Add("AtId", typeof(int));
string line;
while ((line = sr.ReadLine()) != null)
{
System.Diagnostics.Debug.WriteLine(line + "\n");
string[] lineitems = line.Split(";");
DataRow dr = datatable.NewRow();
dr["PPId"] = lineitems[0];
dr["AtId"] = lineitems[1];
datatable.Rows.Add(dr);
}
}
http://prntscr.com/klc4kg, what kind of treatment you are talking about,
– Jonas
Try using this: dr["Atid"] = Convert.Toint32(lineitems[1]);
– Joabe Alexandre
http://prntscr.com/klfa7u , keeps trowing the error xd, i already tryed that before but didnt work, i realy dont know how to fix this
– Jonas