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")
执行下列后
cmd1.commandtext = "Insert Into 编号 (前缀, 顺序号) Values('" & pf & "',1)"
cmd1.ExecuteNonQuery
行的状态 仍然是
DataRowState.Added=true 的状态
退出时提示 保存表!就重复了!! 要执行datatables("编号").").AcceptChanges()吗?