我試圖做一個DataTable,然後向它添加幾行。這裏是我的代碼:DataTable.ImportRow沒有添加行
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);
}
}
}
當我通過程序步驟,dr
成功初始化和值填充,但隨後ImportRow(dr)
後,在dt
的行數仍爲0。我覺得我必須失去了一些東西明顯。這裏有什麼問題?
但是爲什麼? 'ImportRow'聽起來應該是這樣。 – niaher 2015-02-24 13:24:17
ImportRow需要一個已經屬於另一個DataTable的Rows集合的DataRow,並將它帶入另一個DataTable。 – 2017-06-20 20:28:25