DataTable.ImportRow is not adding rows

c#, datatable

Solution

Try this code:

`dt.Rows.Add(dr)`

Problem

I'm trying to make a DataTable and then add a couple rows to it. Here's my code: ``` using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Data; namespace thisNamespace { class Program { static void Main(string[] args) { DataTable dt=new DataTable(); dt.Columns.Add("XYZID"); DataRow dr=dt.NewRow(); dr["XYZID"]=123; dt.ImportRow(dr); dr["XYZID"] = 604303; dt.ImportRow(dr); } } } ``` When I step through the program, `dr` is successfully initialized and populated with values, but then after `ImportRow(dr)`, the count of rows in `dt` is still 0. I feel like I must be missing something obvious. What's going wrong here?

Original source