添加新行并将数据插入行

问题描述 投票:0回答:1

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

例: 第1列=姓名 第2栏=姓氏

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

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

现在我要写入当前添加的行和列1(名称),文本“Bob”然后写入当前行和列2(姓氏),文本“smith”

我似乎无法弄清楚如何做到这一点。任何帮助是极大的赞赏。

vb.net datatable rows
1个回答
2
投票

您可以添加带有指定信息的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)
© www.soinside.com 2019 - 2024. All rights reserved.