I'ld like to generate a salesID in the format ddmmyyyy/0000. The number after
/ should always start from 0001 for a new day.
example
12072016/0001
12072016/0002
12072016/0003
13072016/0001
13072016/0002
13072016/0003
14072016/0001
14072016/0002
I tried reading the if a sale has been made on a date, if not then i start the first sale with the day's date and add 0001 and if there sales have been made then increment it.
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
But I get an error
Invalid attempt to read no data is present
What am I doing wrong? Please help.