Skip to content

Code in VS2012 does not work but works in VS2010

A Repasky

Asked Mar 21, 2013, 11:42 AM EDT1 answer
Share
LinkedInX
 

Here is code that I have used over and over in other programs to create a comma delimited file.  I add it to a record for a number value column.  The code in yellow does not work in VS2012.  So I converted it back to VS2010 and it works.  It was in VS2010 and I converted it to VS2012.  I did not realize right away that the numbered columns did not have a value anymore.    I tried lots of things to get this to work. 

Thank you for anyone that can help on this.  I am supposed to do my development in VS2012.

arep 

C#
                  for (int fcnt = 0; fcnt < dr.FieldCount; fcnt++)
                  {
                     if (fcnt == 21 && name == "Medical")
                     {
                        paidamt = paidamt + (decimal)dr.GetValue(fcnt);
                     }

                     //Handle strings
                     if (dr.GetValue(fcnt).GetType() == typeof(string))
                     {
                        sb.Append("\"");
                        sb.Append(dr.GetValue(fcnt));
                        sb.Append("\"");
                     }
                     //Handle numbers
                     else if (dr.GetValue(fcnt).GetType() == typeof(decimal))
                        sb.Append((double)(dr.GetDecimal(fcnt)));

                        //Handle dates
                     else if (dr.GetValue(fcnt).GetType() == typeof(int))
                     {
                        sb.Append("\"");
                        sb.Append(dr.GetInt32(fcnt).ToDate());
                        sb.Append("\"");
                     }
                     if (fcnt != dr.FieldCount - 1) sb.Append(",");
                  }
                  sw.WriteLine(sb.ToString());  // Print data rows
                  sb.Clear();

                  reccnt++;
               }

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
     

    I got the this program working in VS2012.  I took the code for the method from VS2010 and put it at the end of the class and commented out the bad method with the same name.  It now runs ok in VS2012.   Maybe changing the position in the file of the method.

    arep

    0