-- 作者:vlladz
-- 发布时间:2013/9/12 20:12:00
-- 求助网络环境下的自动编号
Dim sjgs As String \' 时间格式变量 Dim bhbs As String \' 编号标示
Dim nm As String = e.DataTable.name \' 单据名称
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 Dim djb As DataTable \'SQL 查询的临时表 Dim sj As New SQLCommand sj.C \'设置数据源名称 \' sj.commandText = "Select [时间格式] From [单据编号规则] Where 单据名称= \'" & nm & "\'" sj.commandText = "Select [单据名称] From [单据编号规则]" djb = sj.ExecuteReader() If djb.DataRows.Count > 0 Then
sjgs = djb.DataRows(0)("时间格式") 是否写错 提示错误如图,把这个屏蔽就可以通过
MessageBox.Show("获取成功!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information) Else MessageBox.Show("失败!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information) End If End If
\' sjgs = sj.ExecuteScalar() \' If sj.ExecuteScalar = 0 Then \' MessageBox.Show("没有时间格式!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information) \' End If
以下是帮助的内容
pf = Format(dr("下单日期"), sjgs ) \'我想把日期变成变量
Dim cmd2 As New SQLCommand Dim Key As Integer \' Dim nm As String = e.DataTable.name \' 单据名称 cmd1.C \'设置数据源名称 cmd2.C cmd1.commandText = "Select Count(*) From [单据编号表] Where [时间前缀] = \'" & pf & "\' And 单据名称= \'" & nm & "\'" If cmd1.ExecuteScalar = 0 Then \'如果编号表不存在前缀的行,那么增加一行 cmd1.commandtext = "Insert Into 单据编号表(单据名称, 时间前缀, 顺序号) Values(\'" & nm & "\',\'" & pf & "\',1)" cmd1.ExecuteNonQuery End If cmd1.commandText = "Select [顺序号] From [单据编号表] Where [时间前缀] = \'" & pf & "\' And 单据名称 = \'" & nm & "\'" Do Key = cmd1.ExecuteScalar() \'从后台获得顺序号 cmd2.commandText = "Update [单据编号表] Set [顺序号] = " & (Key + 1) & " Where [顺序号] = " & Key & " And [时间前缀] = \'" & pf & "\' And 单据名称 = \'" & nm & "\'" If cmd2.ExecuteNonQuery() > 0 Then \'更新顺序号 Exit Do \'更新成功则退出循环 End If Loop e.DataRow("单据编号") = bhbs & pf & "-" & Format(Key,"0000")
此主题相关图片如下:1.jpg

|