简体   繁体   English

无法将值添加到DataTable C#中的Data.DataRow

[英]Cannot add value to Data.DataRow in DataTable C#

I cant seem to add a value to a datatable in C#. 我似乎无法在C#中向数据表添加值。 I have done my research and cannot figure out what I am missing. 我已经进行了研究,无法弄清我的缺失。 I can print the value to console but when I try to assign and add System.Data.DataRow. 我可以将值打印到控制台,但是当我尝试分配和添加System.Data.DataRow时。 Its probably a simple solution but I cannot figure it out to save the life of me. 这可能是一个简单的解决方案,但我无法弄清楚是否可以挽救我的生命。

worktable is new datatable 工作表是新的数据表

foreach(var ts in timeSeries_ind)
        {
            Bar mbar = ts as Bar;
            DataRow newr = workTable.NewRow();
            newr["Date/Time"] = mbar.DateTime;
            Console.WriteLine(mbar.DateTime);
            workTable.Rows.Add(newr); //newr
            Console.WriteLine(newr.ToString());

        }

Firstline prints fine to console Second when trying to view Data.DataRow 尝试查看Data.DataRow时,Firstline可以很好地打印到控制台Second

You can't print a complete DataRow, you need to specify which field of the DataRow you want to print. 您无法打印完整的DataRow,需要指定要打印的DataRow的哪个字段。 For example (string)newr["Date/Time"] . 例如(string)newr["Date/Time"]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM