禁止多列输入重复值
假定产品表有型号和规格两列,禁止输入型号和规格相同的产品,可以将这个表的DataColChanging事件代码设置为:
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