C#
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
Guest UserRank #1,422 · 1.2K reputationPosted Aug 16, 2011, 10:19 AM EDT
A RepaskyRank #8,108 · 228 reputationPosted Aug 16, 2011, 10:30 AM EDT
The error is:
{"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.
A RepaskyRank #8,108 · 228 reputationPosted Aug 16, 2011, 10:47 AM EDT
+ " " + dr.GetiDB2Char(6).Value.ToString() But if I try to change it to DateTime again, I get the same error. arepGuest UserRank #1,422 · 1.2K reputationPosted Aug 16, 2011, 10:57 AM EDT
A RepaskyRank #8,108 · 228 reputationPosted Aug 16, 2011, 11:43 AM EDT
20100101
Guest UserRank #1,422 · 1.2K reputationPosted Aug 16, 2011, 1:32 PM EDT
DateTime.ParseExact(dr.GetiDB2Char(6).Value.ToString(), "yyyyMMdd", CultureInfo.InvariantCulture)
A RepaskyRank #8,108 · 228 reputationPosted Aug 18, 2011, 7:03 AM EDT
Thanks,
arep