Select Case e.DataCol.name
Case "名称","发布日期"
Dim dr As DataRow = e.DataRow
If dr.IsNull("名称") = False AndAlso dr.IsNull("发布日期") = False Then
If e.DataTable.Compute("Count([_Identify])","名称 = '" & dr("名称") & "' And 发布日期 = '" & dr("发布日期") & "'") > 1 Then
MessageBox.Show("已经存在相同名称和发布日期的行!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
e.DataRow(e.DataCol.Name) = e.OldValue '取消输入
End If
End If
End Select
把这个代码直接放在DataChanged中,虽然能投提示已经存在相同的行,但是同样会保存相同的数据。
Select Case e.DataCol.name
Case "名称","发布日期"
Dim xh As String
Dim gg As String
If e.DataCol.Name= "名称" Then
xh = e.NewValue
gg = e.DataRow("发布日期")
Else
gg = e.NewValue
xh = e.DataRow("名称")
End If
If xh > "" AndAlso gg > "" Then
Dim dr As DataRow = e.DataRow
If e.DataTable.Find("名称 = '" & xh & "' And 发布日期 = '" & gg & "'") IsNot Nothing Then
MessageBox.Show("已经存在相同名称和发布日期的行!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
e.Cancel = True
End If
End If
End Select
把上述代码放在DataChanging中也无效。
[此贴子已经被作者于2017/1/11 12:51:21编辑过]