My goal is to trim all string datatypes within my dataset and then replace the “untrimmed” with the trimmed.
I encounter the following error:
“ArgumentException was unhandled – String was not recognized as a valid DateTime.Couldn’t store <> in DateofBirth Column. Expected type is DateTime.”
when I run the following code:
foreach (DataRow y in ds.Tables[0].Rows)
{
for (int i = 0; i < ds.Tables[0].Columns.Count -1; i++)
{
if (y[i].GetType() != typeof(DateTime))
{
string strTrim = y[i].ToString().Trim();
y[i] = strTrim;
}
}
}
I’m sure I’m on the right track, I just can’t manage to crack it :/
Any help will be appreciated!
If you’re just looking for strings why are you checking for
DateTime? Try: