以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  DataColChanged按类别生成编码 怎么转换成sql语句写法呢?  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=184589)

--  作者:cnsjroom
--  发布时间:2022/12/14 17:19:00
--  DataColChanged按类别生成编码 怎么转换成sql语句写法呢?
 

Select e.DataCol.Name
    Case
"类别"
       
If e.DataRow.IsNull("类别") Then
            e.
DataRow("编号") = Nothing
        Else
            Dim
lb As String = e.DataRow("类别")
            If
e.DataRow("编号").StartsWith(lb) = False \'如果单据编号前缀不符
               
Dim max As String
               
Dim idx As Integer

                max = e.DataTable.Compute("Max(编号)","类别 = \'" & lb & "\' And [_Identify] <> " & e.DataRow("_Identify")) \'取得该类别的最大编号
               
If max > "" Then \'如果存在最大编号
                    idx = CInt(max.Substring(
2,3)) + 1 \'获得最大编号的后三位顺序号,并加1
               
Else
                    idx =
1 \'否则顺序号等于1
               
End If
                e.
DataRow("编号") = lb & Format(idx,"000")
            End
If
        End
If
End
Select

 

 

DataColChanged按类别生成编码  怎么转换成sql语句写法呢?


--  作者:cnsjroom
--  发布时间:2022/12/14 17:31:00
--  回复:(cnsjroom)DataColChanged按类别生成编码 怎...

Dim lb As String = "DY"
Dim max As String
Dim idx As Integer
Dim cmd As New SQ LCommand
cmd.Conn ectio nNa me = "主数据源"
cmd.Comm andText = "Se lect * From 台账"
Dim dt As DataTable = cmd.ExecuteReader()
Dim dr As DataRow = dt.DataRows(dt.DataRows.Count - 1) \'获得最后一行
output.show(dr("_Identify"))
max = dt.Compute("Max(编号)","分类代码 = \'" & lb & "\'And [_Identify] <> " & dr("_Identify"))  \'取得该类别的最大编号
If max > "" Then \'如果存在最大编号
    idx = CInt(max.Substring(2,3)) + 1 \'获得最大编号的后三位顺序号,并加1
Else
    idx = 1 \'否则顺序号等于1
End If
output.show(lb & Format(idx,"000"))

 

---------------------------
版本:2022.1.30.2
---------------------------
代码执行出错,错误信息:

 

System.InvalidCastException: 从字符串“ZBD”到类型“Integer”的转换无效。 ---> System.FormatException: 输入字符串的格式不正确。

   在 Microsoft.VisualBasic.CompilerServices.Conversions.ParseDouble(String Value, NumberFormatInfo NumberFormat)

   在 Microsoft.VisualBasic.CompilerServices.Conversions.ToInteger(String Value)

   --- 内部异常堆栈跟踪的结尾 ---

   在 Microsoft.VisualBasic.CompilerServices.Conversions.ToInteger(String Value)

   在 UserCode.Test()
---------------------------
确定  
---------------------------

[此贴子已经被作者于2022/12/14 17:34:45编辑过]

--  作者:有点蓝
--  发布时间:2022/12/14 17:33:00
--  
dim sql as string = "select Max(编号) from 表A where 类别 = \'" & lb & "\' And [_Identify] <> " & e.DataRow("_Identify")
--  作者:cnsjroom
--  发布时间:2022/12/14 17:40:00
--  回复:(有点蓝)dim sql as string = "select M...

Dim lb As String = "DY"
Dim idx As Integer
Dim cmd As New  SQLCommand
cmd.Con ne ctio n Name = "主数据源"
cmd.CommandText = "Se lect * From 办案装备_管理台账"
Dim dt As DataTable = cmd.ExecuteReader()
Dim dr As DataRow = dt.DataRows(dt.DataRows.Count - 1) \'获得最后一行
output.show(dr("_Identify"))
Dim max As String = "sele ct Max(编号) from 办案装备_管理台账 where 分类代码 = \'" & lb & "\' And [_Identify] <> " & dr("_Identify")
output.show(max)
If max > "" Then \'如果存在最大编号
    idx = CInt(max.Substring(2,3)) + 1 \'获得最大编号的后三位顺序号,并加1
Else
    idx = 1 \'否则顺序号等于1
End If
output.show(lb & Format(idx,"000"))

 

输出得到:

8
sel ect Max(编号) from 办案装备_管理台账 where 分类代码 = \'DY\' And [_Identify] <> 8


提示错误:

System.InvalidCastException: 从字符串“lec”到类型“Integer”的转换无效。 ---> System.FormatException: 输入字符串的格式不正确。

   在 Microsoft.VisualBasic.CompilerServices.Conversions.ParseDouble(String Value, NumberFormatInfo NumberFormat)

   在 Microsoft.VisualBasic.CompilerServices.Conversions.ToInteger(String Value)

   --- 内部异常堆栈跟踪的结尾 ---

   在 Microsoft.VisualBasic.CompilerServices.Conversions.ToInteger(String Value)

   在 UserCode.Test()


--  作者:cnsjroom
--  发布时间:2022/12/14 17:48:00
--  回复:(有点蓝)dim sql as string = "select M...

谢谢老师  按照老师指导 修正如下  问题得以解决!

 

Dim lb As String = "DY"
Dim idx As Integer
Dim cmd As New SQLCommand
cmd.Con nec tio nNa me = "主数据源"
cmd.CommandText = "Sel ect * From 办案装备_管理台账"
Dim dt As DataTable = cmd.ExecuteReader()
Dim dr As DataRow = dt.DataRows(dt.DataRows.Count - 1) \'获得最后一行
output.show(dr("_Identify"))
cmd.CommandText = "sel ect Max(编号) from 办案装备_管理台账 where 分类代码 = \'" & lb & "\' And [_Identify] <> " & dr("_Identify")
Dim max As String
max = cmd.ExecuteScalar()
output.show(max)
If max > "" Then \'如果存在最大编号
    idx = CInt(max.Substring(6,3)) + 1 \'获得最大编号的后三位顺序号,并加1
Else
    idx = 1 \'否则顺序号等于1
End If
output.show("BAZB" & lb & Format(idx,"000"))