Foxtable(狐表)用户栏目专家坐堂 → 获取编号的方法中的错误


  共有11136人关注过本帖平板打印复制链接

主题:获取编号的方法中的错误

帅哥哟,离线,有人找我吗?
kgd815
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:婴狐 帖子:49 积分:724 威望:0 精华:0 注册:2011/4/30 11:55:00
获取编号的方法中的错误  发帖心情 Post By:2011/5/17 16:06:00 [只看该作者]

Public Function GetSystemDate() As Date
Dim aD As Date
Dim cmd1 As New SQLCommand
'设置数据源名称
cmd1.C
cmd1.commandText = "Select getdate()"
ad = cmd1.ExecuteScalar
Return ad
End Function


'编码规范类型名    前缀  日期格式  数据位数
Public Function GetSystemBM(bmType As String,byval PF As String,byval DFormat As String ,byval sNum As Integer) As String
Dim bm As String
Dim dt As DataTable
Dim Key As Integer
Dim Adate As String
Dim aWhere As String
Dim Astr As new String("0",snum)
Dim sDate As Date

Dim cmd1 As New SQLCommand
Dim cmd2 As New SQLCommand

sdate=GetSystemDate()


'设置数据源名称
cmd1.C
cmd2.C

'检查是否存在此编码规范 如果不存在 则添加
cmd1.commandText = "Select Count(*) From [系统编码] Where [前缀] = '" & PF & "'"
If cmd1.ExecuteScalar = 0 Then '如果编号表不存在前缀的行,那么增加一行
    cmd1.commandtext = "Insert Into 系统编码(前缀, 顺序号,日期,日期格式) Values('" & PF & "',1,'" & format(sdate,DFormat) & "','" &  DFormat & "')"
    cmd1.ExecuteNonQuery
End If

'获取并更新编码规范
cmd1.commandText = "Select [顺序号][日期][日期格式] From [系统编码] Where [前缀] = '" & PF & "'"



Do
    dt = cmd1.ExecuteReader()'从后台获得顺序号,日期,日期格式

    MessageBox.SHOW (“下面出错啦”)

    If format(sDate,dt.DataRows(0)("日期格式"))<>dt.DataRows(0)("日期")  Then
        key=1
        Adate=dt.DataRows(0)("日期")
    Else
        key=dt.DataRows(0)("顺序号") +1
        Adate= format(sDate,  dt.DataRows(0)("日期格式"))
    End If   
    
    aWhere= "[顺序号] = " & dt.DataRows(0)("顺序号") & " And [日期] = '" & dt.DataRows(0)("日期")  & "' And [前缀] = '" & pf & "'"
    cmd2.commandText = "Update [系统编码] Set [顺序号] = " & Key  & ",[日期] = " & Adate & " Where " & aWhere
    If cmd2.ExecuteNonQuery() > 0 Then '更新顺序号
        Exit Do '更新成功则退出循环
    End If
Loop
'返回编码
bm = PF & Adate & Format(Key,Astr)
Return bm
End Function

请教专家怎么解决


 回到顶部