auto generating number
-
hello i have this problem with auto generation number via using function the coding below is converted from vb6 and it is working in vb6 Public Function autoorderno() As String
Dim orderno As String
Dim ordering As New Class1
Dim order As New ADODB.Recordset
order.Open "SELECT * FROM orders", cn, adOpenDynamic, adLockOptimistic, adCmdText
auto = "000000"
Do While Not order.EOF
order.Find "orderno ='Ord" & auto & "'"
If Not order.EOF Then
auto = Format(Str(Val(Mid$(auto, 5) + 1)), "000000")
Else
autoorderno = "Ord" + auto
Exit Function
End If
Loop
autoorderno = "Ord" + auto
Set order = Nothing
End Functionbut some how in vb.net it say "value cannot be generated" may i know what is wrong with the coding thank you in advance Gary
-
hello i have this problem with auto generation number via using function the coding below is converted from vb6 and it is working in vb6 Public Function autoorderno() As String
Dim orderno As String
Dim ordering As New Class1
Dim order As New ADODB.Recordset
order.Open "SELECT * FROM orders", cn, adOpenDynamic, adLockOptimistic, adCmdText
auto = "000000"
Do While Not order.EOF
order.Find "orderno ='Ord" & auto & "'"
If Not order.EOF Then
auto = Format(Str(Val(Mid$(auto, 5) + 1)), "000000")
Else
autoorderno = "Ord" + auto
Exit Function
End If
Loop
autoorderno = "Ord" + auto
Set order = Nothing
End Functionbut some how in vb.net it say "value cannot be generated" may i know what is wrong with the coding thank you in advance Gary
GaryKoh wrote: but some how in vb.net it say "value cannot be generated" Where does this message come from? It will not be generated by the code you posted, which is VB6 code, not VB.NET... There is nothing wrong with this code other than it is not very effecient. Order numbers should never be reused, even if they have been deleted. This code will find holes in the order number sequence and re-use them. The detabase should have been written to generate ID's itself. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
-
GaryKoh wrote: but some how in vb.net it say "value cannot be generated" Where does this message come from? It will not be generated by the code you posted, which is VB6 code, not VB.NET... There is nothing wrong with this code other than it is not very effecient. Order numbers should never be reused, even if they have been deleted. This code will find holes in the order number sequence and re-use them. The detabase should have been written to generate ID's itself. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
-
hello dave so how i know you would answer thank you just want to know does the msdn webpage provide the suitable tutorial or faq i need to get the random number result i wish as the coding i provided? can i have a link to the webpage please thank you
There is no one article that will do what you want. Your requirements are a combination of a bunch of smaller techniques that need to be put together correctly. What's with the "random" order number? I've never seen a requirement where the order number must be random. I've only seen "serial number" type order numbers. How I've seen it done in the past, and I've done this myself, is to have a seperate table in the database that holds your databases status and statistics, such as the last used order number. Your code would call a stored procedure in the database that retrieves the last used order number, increments it, stores it back in the table and creates a blank order record in the "orders" table, using the newly created order number. Then this record is sent back to your program as a dataset (SELECT statement). Your app then fills in the details of the order and writes back the order record, without having to worry about the order number at all. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome