DataTable.ImportRow不加入行 [英] DataTable.ImportRow is not adding rows
本文介绍了DataTable.ImportRow不加入行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图做一个DataTable,然后添加一对夫妇行了。这里是我的代码:
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);
}
}
}
当我通过程序步骤,博士
成功初始化和值填充,但再经过 ImportRow(DR)
,计数在行的DT
仍是0。我觉得我必须失去了一些东西明显。发生了什么事错在这里。
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?
推荐答案
试试这个代码:
dt.Rows.Add(DR)
这篇关于DataTable.ImportRow不加入行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文