A Repasky

A Repasky

  • 1.7k
  • 231
  • 143.5k

Cannot convert date to string with AS400

Aug 16 2011 1:54 PM
Here is the code: 




         OpenMC400();
         iDB2Command cmd = new iDB2Command();
         cmd.Connection = cn;
         cmd.CommandText = @"call UPMITGCUS.RETRIEVE_MEMBER_SUMMARY(@insubno, @inperno, @ingroup, @insubgroup, @inplancode, @indate, @ques)";
         cmd.CommandType = System.Data.CommandType.Text;
         cmd.DeriveParameters();
         //Set the parameter values
         cmd.Parameters["@insubno"].Value = memberNbr; 
        cmd.Parameters["@inperno"].Value = person;
         cmd.Parameters["@ingroup"].Value = group;
         cmd.Parameters["@insubgroup"].Value = subGroup;
         cmd.Parameters["@inplancode"].Value = plancode;
         cmd.Parameters["@indate"].Value = date;
         iDB2DataReader dr = cmd.ExecuteReader();
         while (dr.Read())
         { 
           Console.WriteLine(dr.GetiDB2Char(0).Value.ToString()
               + " " + dr.GetiDB2Char(1).Value.ToString()
               + " " + dr.GetiDB2Char(2).Value.ToString()
               + " " + dr.GetiDB2Char(3).Value.ToString()
               + " " + dr.GetiDB2Char(4).Value.ToString()
               + " " + DateTime.Parse(dr.GetiDB2Date(6).ToNativeFormat())
               );
         }




Here is the error:
{"String was not recognized as a valid DateTime."}



When converting a string to DateTime, parse the string to take the date before putting each variable into the DateTime object.


I have tried different things and it still gives me the error. The other variables come out fine when date is commented out.


Thanks for any help.
arep




Answers (7)