【问题标题】:Adding New Row and inserting data to row添加新行并将数据插入行
【发布时间】:2018-03-05 06:26:46
【问题描述】:

我有一个现有的数据表,其中预定义了两列。

示例:
第 1 列 = 名称
第 2 列 = 姓氏

我的数据表中当前没有行。

Datatable.Rows.Add - 将一行添加到我的集合中

现在我想用文本“Bob”写入当前行和第 1 列(姓名),然后用文本“smith”写入当前行和第 2 列(姓氏)

我似乎无法弄清楚如何做到这一点。非常感谢任何帮助。

【问题讨论】:

标签: vb.net datatable rows


【解决方案1】:

您可以添加带有指定信息的DataRow

Dim dtTable As New DataTable

'create a new data row.
Dim drNewRow As DataRow = dtTable.NewRow

'specify the information of the new row.
drNewRow("Name") = "Bob"
drNewRow("Surname") = "Smith"

'add the new row with specified information to the table.
dtTable.Rows.Add(drNewRow)

【讨论】:

  • 谢谢你,虽然我得到了这个错误:这一行已经属于这个表。
  • 上面的例子应该可以确保你没有两次添加同一行。
  • 好的,这可能是问题,因为我需要添加多行,然后将数据添加到每一行。目前对我有用的是首先添加行,然后循环数据表并添加值。谢谢
猜你喜欢
  • 2020-10-29
  • 1970-01-01
  • 2011-04-24
  • 2014-01-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-01-03
  • 2014-07-02
相关资源
最近更新 更多