This is probably a little difficult to explain, but row["PZN"] is an object - not anything derived from an object. It is also a fairly special object in that when you assign to it, it gets converted to the underlying type for the DataTable - in this case,
int
, I suspect from the name. So, when you read it back and ToString it, the underlying datatype is used again, and a standard int-to-string convertion is done.
Try it yourself:
int i = 0;
foreach (DataRow row in dt.Rows)
{
string s = i.ToString().PadLeft(7, '0');
i++;
object o = s;
row["myInt"] = s;
Console.WriteLine("{0}:{1}:{2}", s, o.ToString(), row["myInt"]);
row["myStr"] = s;
Console.WriteLine("{0}:{1}:{2}", s, o.ToString(), row["myStr"]);
}
The results are:
0000000:0000000:0
0000000:0000000:0000000
0000001:0000001:1
0000001:0000001:0000001
0000002:0000002:2
0000002:0000002:0000002