向DATAGRID中动态添加记录,无数据库连接
本代码为VS2003.net下的已通过测试
mycmd.CommandText = "select '" + "value1" + "','" + "value2" + "','" + "value3" + "','" + "value4" + "','" + "value5" + "','" + "value6" + "'"
Dim apter As New SqlDataAdapter(mycmd.CommandText, myconn)
Dim dsin As New DataSet
apter.Fill(dsin, "table")
dsin.Clear()
Me.DataGrid1.DataSource = dsin.Tables("table")
Dim dtr As DataRow
dtr = dsin.Tables("table").NewRow
dtr(0) = val_col0
dtr(1) = val_col1
dtr(2) = val_col2
dtr(3) = val_col3
dtr(4) = val_col4
dtr(5) = "OK"
dsin.Tables("table").Rows.InsertAt(dtr, DataGrid1.CurrentRowIndex + 1)
Me.DataGrid1.ReadOnly = False
Me.DataGrid1.Refresh()