且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何将新行添加到数据表 vb.net

更新时间:2023-12-01 08:51:10

以下是向第一列使用 AutoIncrement 的数据表添加新行的示例:

Here is an example of adding a new row to a datatable that uses AutoIncrement on the first column:

定义表结构:

    Dim dt As New DataTable
    dt.Columns.Add("ID")
    dt.Columns.Add("Name")
    dt.Columns(0).AutoIncrement = True

添加新行:

    Dim R As DataRow = dt.NewRow
    R("Name") = txtName.Text
    dt.Rows.Add(R)
    DataGridView1.DataSource = dt