.net 将行1乘1添加到绑定的datatable最终会复制上一行的信息
我有一个绑定数据表:.net 将行1乘1添加到绑定的datatable最终会复制上一行的信息,.net,vb.net,.net,Vb.net,我有一个绑定数据表: With DS .Tables.Add(New DataTable With {.TableName = "Changes"}) End With Using iConn As New OleDbConnection(ConnString) Using iDA As New OleDbDataAdapter(iSelectString, Conn) iDA.MissingSchemaAction = MissingSchemaAction
With DS
.Tables.Add(New DataTable With {.TableName = "Changes"})
End With
Using iConn As New OleDbConnection(ConnString)
Using iDA As New OleDbDataAdapter(iSelectString, Conn)
iDA.MissingSchemaAction = MissingSchemaAction.AddWithKey
iDA.FillSchema(DS.Tables("Changes"), SchemaType.Source)
iDA.Fill(DS.Tables("Changes"))
iBS.DataSource = DS.Tables("Changes")
DGVDV = DS.Tables("Changes").DefaultView
With DataGridView1
.DataSource = iBS
End With
End Using
End Using
以及一些绑定的文本框:
dtpDate.DataBindings.Add("Text", iBS, "HireDate")
txtEmpID.DataBindings.Add("Text", iBS, "EmployeeID")
txtField1.DataBindings.Add("Text", iBS, "Field1")
txtField2.DataBindings.Add("Text", iBS, "Field2")
txtField3.DataBindings.Add("Text", iBS, "Field3")
txtField4.DataBindings.Add("Text", iBS, "Field4")
txtEmail.DataBindings.Add("Text", iBS, "EmailAddresses")
txtNotes.DataBindings.Add("Text", iBS, "OtherNotes")
txtCorrespondence.DataBindings.Add("Text", iBS, "Correspondence")
到目前为止,所有这些都运行得很好。问题是当我尝试添加新行时
我有一个Form2,其中有几个文本框,与我的DataTable中的列相对应,我将在下面的小节中介绍:
Private Sub frm2_SimulateForm1ButtonClick() Handles AddingNew.SimulateForm1ButtonClick
Form2.Hide()
Dim drNewRow As DataRow
drNewRow = DS.Tables("Changes").NewRow
drNewRow.Item("HireDate") = AddingNew.TransitionDate.ToShortDateString()
drNewRow.Item("EmployeeID") = AddingNew.EmpID
drNewRow.Item("Field1") = AddingNew.Field1
drNewRow.Item("Field2") = AddingNew.Field2
drNewRow.Item("Field3") = AddingNew.Field3
drNewRow.Item("Field4") = AddingNew.Field4
drNewRow.Item("EmailAddresses") = AddingNew.Email
drNewRow.Item("OtherNotes") = AddingNew.Notes
drNewRow.Item("Correspondence") = AddingNew.Correspondence
drNewRow.Item("Status") = "Scheduled"
DS.Tables("Changes").Rows.Add(drNewRow)
DS.Tables("Changes").AcceptChanges()
End Sub
这第一次效果很好。但每隔一次,其他注释和通信字段都会从上一行复制。有人能给我建议吗?我刚刚不得不修改,现在一切都正常了。我无法重现你的问题。尝试清理并重建解决方案。完成-问题仍然存在。除了信件和便笺,其他所有的字段都添加得很完美。哦,上帝。我想我明白了。在显示表单2之前,我必须编辑iBS.EndEdit。如果您有答案,请关闭此答案。