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
请教专家怎么解决