If a DataTable is
null
then you can't copy anything to it: there isn't anything to copy into!
It's a bit like a pocket: you have a pocket in your shirt, which you use to hold a pen. If you reach into the pocket and find there isn't a pen there, you can't sign your name on a piece of paper - and you will get very funny looks if you try!
But what you are trying to do is reach into a pocket while you aren't even wearing a shirt! You can't check the pocket for a pen, because the pocket isn't there at all.
If you want to copy data to a DataTable and the variable is
null
, you have to create an instance of a table to add it to.
In this case, all you need to do is use the Add method:
else
{
dtTable.Rows.Add (from DataRow dr in dtDetails.Rows
where dr["ID"].ToString() == Id
select dr)