我希望以ddmmyyyy / 0000格式生成salesID。
之后的数字/应始终从0001开始新的一天。
示例
12072016/0001
12072016/0002
12072016/0003
13072016/0001
13072016/0002
13072016/0003
14072016/0001
14072016/0002
我尝试阅读如果在某个日期进行了销售,如果没有,那么我就开始了 首次销售与当天的日期并添加0001,如果已经进行了销售,则增加它。
myConnection.Open()
Dim sel As SqlCommand = New SqlCommand("select Code as Code from sales where saledate ='" & Format(Today, "yyyy-MM-dd") & "'", myConnection)
Dim dr As SqlDataReader = sel.ExecuteReader
If dr.HasRows Then
While dr.Read
dmyConnection.Open()
Dim seld As SqlCommand = New SqlCommand("select max(Code) as Code from sales where saledate='" & Format(Today, "yyyy-MM-dd") & "'", dmyConnection)
Dim r As SqlDataReader = seld.ExecuteReader
code = Format((r("Code") + 1), "0000")
Sales_ID = (Format(Today, "ddMMyyyy")) & "/" & code
SalesID.Text = Sales_ID
dmyConnection.Close()
End While
dr.Close()
myConnection.Close()
Else
dr.Close()
code = "0001"
Sales_ID = (Format(Today, "ddMMyyyy")) & "/" & code
SalesID.Text = Sales_ID
myConnection.Close()
End If
但是我收到了错误
无效读取无数据的尝试
我做错了什么?请帮忙。