C# 如何更新数据表的单元格值?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9309798/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-09 06:50:18  来源:igfitidea点击:

How can i update cell value of data table?

c#.netado.netdatatable

提问by bhaveshkac

How can i update cell value of data table

如何更新数据表的单元格值

if ((sr_no == "") && (customer_name != ""))
{
  string contact_no = SheetData.Tables[0].Rows[row].ItemArray[3].ToString();
  Records.Rows[0].ItemArray[2]                                      
}

i want to update cell of datatable if contact_no fround in next row

如果在下一行中没有找到联系人,我想更新数据表的单元格

采纳答案by Davide Piras

if Recordsis your DataTabledo this:

如果RecordsDataTable这样做:

Records.Rows[i][j] = value;

this does not answer the whole question but shows you how to set a value in a DataTable "cell".

这并没有回答整个问题,而是向您展示了如何在数据表“单元格”中设置一个值。

you are using the ItemArraywhich is not needed because once you have the right Row you can simply access its columns withh []

您正在使用ItemArray不需要的,因为一旦您拥有正确的行,您就可以简单地访问其列[]

you can elaborate more and find out the final solution based on this hint.

您可以详细说明并根据此提示找出最终解决方案。

回答by Sponsor

If you use Records.Rows[0].ItemArray[2] = valuethis won't work, but if you use Records.Rows[0][2] = valuethis works perfectly.

如果你使用Records.Rows[0].ItemArray[2] = value它不会工作,但如果你使用Records.Rows[0][2] = value它完美。