GetChangesはrowstateの状態を引数にしてその状態の行だけ取り出します。
代入する先はtableです。
tableのデータを取り出してるのだから当然ですね。
ソース
Imports System.Data.SqlClient
Public Class Form1
Dim cn As New SqlConnection(
“Data Source=(local)\SQL;” +
“Initial Catalog=ADO;” +
“Integrated Security=True;Pooling=False”)
Dim table As New DataTable()
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim adapter As New SqlDataAdapter()
adapter.SelectCommand = New SqlCommand()
adapter.SelectCommand.CommandText = “select * from meibo ”
adapter.SelectCommand.Connection = cn
adapter.Fill(table)
DataGridView1.DataSource = table
Dim dr As DataRow = table.NewRow
dr(“number”) = CInt(TextBox1.Text)
dr(“name”) = TextBox2.Text
dr(“部署コード”) = TextBox3.Text
table.Rows.Add(dr)
MsgBox(dr.RowState)
Dim table2 As New DataTable()
table2 = table.GetChanges(DataRowState.Added)
DataGridView2.DataSource = table2
End Sub
End Class
テキストボックスに入力して実行してます。
テキストボックスの入力例
1 数字
文字列
文字列
ここではテーブル1に追加した行をGetChangesで取り出して
テーブル2に代入してデータグリッドビュー2に表示しています。