以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  请问大神们在SQLTable不能使用网络环境下的复杂编号这个功能吗?  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=42726)

--  作者:lhpc120
--  发布时间:2013/11/20 13:13:00
--  请问大神们在SQLTable不能使用网络环境下的复杂编号这个功能吗?

问题RT,使用下面代码再SQLTable中的BeforeSaveDataRow事件中,为什么提示 对象名  \'编号\' 无效啊,而且也关闭不了。

 

Dim dr As DataRow = e.DataRow
Dim
pf As String
If
dr.RowState <> DataRowState.Added Then \'如果不是新增行
   
Return \'那么返回
ElseIf
dr.IsNull("日期") Then \'如果没有输入日期
    e.Cancel =
True \'取消保存此行
    MessageBox.Show(
"必须输入日期!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
    Return
Else

    pf = Format(dr(
"日期"),"yyMM") \'否则获得编号的前缀,两位年,两位月
End
If
Dim
cmd1 As New SQLCommand
Dim
cmd2 As New SQLCommand
Dim
Key As Integer
cmd1.ConnectionName =
"编号" \'设置数据源名称
cmd2.ConnectionName =
"编号"
cmd1.commandText =
"Select Count(*) From [编号] Where [前缀] = \'" & pf & "\'"
If
cmd1.ExecuteScalar = 0 Then \'如果编号表不存在前缀的行,那么增加一行
   
cmd1.commandtext = "Insert Into 编号 (前缀, 顺序号) Values(\'" & pf & "\',1)"
   
cmd1.ExecuteNonQuery
End If

cmd1
.commandText = "Select [顺序号] From [编号] Where [前缀] = \'" & pf & "\'"
Do
    Key
= cmd1.ExecuteScalar() \'从后台获得顺序号
    cmd2
.commandText = "Update [编号] Set [顺序号] = " & (Key + 1) & " Where [顺序号] = " & Key & " And [前缀] = \'" & pf & "\'"
    If
cmd2.ExecuteNonQuery() > 0 Then \'更新顺序号
        Exit Do
\'更新成功则退出循环
    End If
Loop

e.
DataRow("编号") = pf & "-" & Format(Key,"0000")

 

补充一下,为什么再这里的表明用[]括号起来呢?而不是用{}

[此贴子已经被作者于2013-11-20 13:15:21编辑过]

--  作者:unverse
--  发布时间:2013/11/20 13:28:00
--  

一般字段 用【】 ,表名用{},如果是SQL后台可以不加,括号 吧。如果是内部数据源得吧,我记得好像是这么回事

 


--  作者:lhpc120
--  发布时间:2013/11/20 13:34:00
--  
Update [编号] Set 这种地方应该是表名,不是还是用的[]吗?
--  作者:lhpc120
--  发布时间:2013/11/20 13:39:00
--  
知道原因了,谢谢~~~  原因是我自己的错误