下面是我获取季度的代码,并且效果很好
Private Function GetQuarter() As String
initializeCon()
Dim dt As DateTime
Return ((dt.Month - 1) / 3) + 1
End Function
下面是我获取年份的代码,它运行良好
Private Function AutoYear() As String
initializeCon()
Dim d As Date = Now
Return d.ToString("yy")
End Function
下面是我的自动递增编号代码。这是我的问题,第一次尝试将其保存到数据库中,但是第二次下面的代码出错,并说从字符串191001到类型Double的转换无效,并且该错误涉及代码Return ProdID。有人可以帮我吗?
Private Function GetAutoNumber() As String
initializeCon()
Try
cmd = New SqlCommand("SELECT LotNo FROM ProductionOrder ORDER BY ID", con)
cmd.ExecuteNonQuery()
dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
If (dr.Read) = True Then
Dim id As Integer
id = dr(0) + 1
ProdID = id.ToString("000")
ElseIf IsDBNull(dr) Then
ProdID = "001"
Else
ProdID = "001"
End If
Catch ex As Exception
MsgBox(ex.Message)
Finally
cmd.Dispose()
con.Close()
End Try
Return ProdID
End Function
要获得191001,我只是称呼它们为函数名。 19是年份,1是季度,001是控制编号。