以文本方式查看主题 - Foxtable(狐表) (http://foxtable.com/bbs/index.asp) -- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2) ---- [求助]三个组合查重代码 (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=91635) |
-- 作者:benwong2013 -- 发布时间:2016/10/15 11:19:00 -- [求助]三个组合查重代码 有三个列,分别为单位代码、仓库代码、物料编号,希望当这个列任何一列输入新数据的时候,将用三个组合成为一个组合对表进行查重,有重复将提示,两个组合我可以实现,三个的时候试了几次都有问题,请帮忙修正以下代码,谢谢! 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("已经存在相同物料!","提示") e.DataRow.Delete End If End If End Select |
-- 作者:有点蓝 -- 发布时间:2016/10/15 11:37:00 -- 代码改到DataColChanging事件 Select Case e.DataCol.name Case "仓库代码","物料编号","单位代码" Dim filter As String filter = "仓库代码" & IIF(e.DataRow.IsNull("仓库代码")," is null "," = \'" & e.DataRow("仓库代码") & "\'") filter &= "and 物料编号" & IIF(e.DataRow.IsNull("物料编号")," is null "," = \'" & e.DataRow("物料编号") & "\'") filter &= "and 单位代码" & IIF(e.DataRow.IsNull("单位代码")," is null "," = \'" & e.DataRow("单位代码") & "\'") If not filter.Contains("=") Then Return Dim dr As DataRow = e.DataRow If e.DataTable.Find(filter) IsNot Nothing Then MessageBox.Show("已经存在相同物料!","提示") e.Cancel = True End If End Select |