改成
If e.DataCol.Name = "合同编号" Then Dim dr As DataRow dr = e.DataTable.sqlFind("合同编号 = '" & e.NewValue & "'") If dr IsNot Nothing Then MessageBox.Show("此合同编号已经存在!") e.Cancel = True End IfEnd If