locked
Input string was not in a correct format. RRS feed

  • Question

  • User-702498187 posted

    if (this.DataCenterLaborFileUpload.HasFile)                

    {                 var extension = Path.GetExtension(DataCenterLaborFileUpload.FileName);                

    string currentName = "";                

    decimal currentHours = 0.00M;                 

    if (extension == ".csv")                

    {                     StreamReader csvreader = new StreamReader(DataCenterLaborFileUpload.FileContent);                    

    DataTable dt = new DataTable();                    

    dt.Columns.Add("txtName");                    

    dt.Columns.Add("txtHours");

                        while (!csvreader.EndOfStream)                    

    {                         DataRow dr = dt.NewRow();

                            var line = csvreader.ReadLine();                        

                            var values = line.Split(',');                                                                            

    if (values[0].Trim() != "Pers.No.")                            

    {                                 if (values[1].Trim() == currentName)                               

      {                                     currentHours = currentHours + Convert.ToDecimal(values[9].Trim());

    This is where it is stopping and I'm getting the error "Input string was not in a correct format"

    I am reading in a .csv file.

    Saturday, March 14, 2015 12:19 PM

Answers

  • User-821857111 posted

    The value that you are trying to convert to a decimal cannot be converted to that type. You should use the debugger to find out what the actual value is. That should help you resolve the issue.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, March 14, 2015 3:32 PM