以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  [求助]关于字符串检查的代码  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=72449)

--  作者:huangfanzi
--  发布时间:2015/7/30 12:56:00
--  [求助]关于字符串检查的代码
表中有一列 卷号 ,由8个字符组成,例如 CS150001,其中150001部分必须是唯一值,比如不允许出现CR150001
DataColChanged事件中写了以下代码,但显然是错误的,请老师修改一下:
If e.DataCol.Name = "卷号" Then
    Dim dr As DataRow
    dr = e.DataTable.SQLFind("[卷号].Contains(" & e.NewValue.SubString(2,6) & ")\'And [_Identify] <> " & e.DataRow("_Identify") )
    If dr IsNot Nothing Then
        MessageBox.Show("所录入的卷号已经存在并且保存于后台,请检查后继续操作!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
        e.DataRow("卷号") = e.OldValue
    End If
End If

--  作者:czy
--  发布时间:2015/7/30 14:55:00
--  

这样试试

 

dr = e.DataTable.SQLFind("[卷号] Like \'" & e.NewValue.SubString(2,6) & "%\'")


--  作者:大红袍
--  发布时间:2015/7/31 1:08:00
--  

sqlserver数据库这样写

 

dr = e.DataTable.SQLFind("SubString([卷号],3,6) = \'" & e.NewValue.SubString(2,6) & "\' And [_Identify] <> " & e.DataRow("_Identify") )


 

Accesss这样写

 

dr = e.DataTable.SQLFind("Mid([卷号],3,6) = \'" & e.NewValue.SubString(2,6) & "\' And [_Identify] <> " & e.DataRow("_Identify") )

[此贴子已经被作者于2015/7/31 1:08:03编辑过]