.net - 为数据表中的所有行设置值,无需 for 循环

标签 .net vb.net datatable for-loop

我试图在不使用 for 循环的情况下为数据表中单个列的所有行设置相同的值。任何人都可以建议任何更快的方法来实现相同的目标。

最佳答案

是的,即使没有循环,这是可能的!这可以通过 Expression 属性来完成。请记住,字符串值应该用引号引起来,否则它会将其视为另一个列名。 1

这将使用字符串值a设置列“col1”:

preview.Columns["col1"].Expression = "'a'";

这将在“col1”中显示“col2”列的值:

preview.Columns["col1"].Expression = "col2";

关于.net - 为数据表中的所有行设置值,无需 for 循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5063551/

相关文章:

c# - 在 .NET 中捕获存储过程打印输出

c# - 使用.net框架和azure创建实时Web应用程序 - 非常困惑

vb.net - 使用 System.Reflection.Emit 在 Windows.Forms 中显示 MessageBox

c# - Datatable 选项导致 "Missing operand after ' s' operator"error

javascript - Jquery 数据表 : Replacing the buttons with icons at the same location

c# - HttpWebResponse.LastModified 的默认值

c# - 如何将可空类型传递给 P/调用函数

vb.net - 仅在使用 OpenFileDialog 时返回 FileName

vb.net - Visual Basic 随机猜数游戏

c# - AsEnumerable().Take