Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
Hello
i'm using VB.net 2008 and Access DB as backend
on this software i'm trying to generate automatically number as invoice number or ID
can you help me on doing this
note : i don't need to use ID Field (Automatic ID from Access itself )
i need it to be like this
 
last invoice number is 1234
i nwant to create an invoice , so one of the textboxes will be 1235 (Last Invoice Number + 1)
 
sorry for not clear English
i hope that you got me
 
Thanks
Posted 15-Jul-11 8:57am
Comments
Joan Murt at 7-Aug-12 10:25am
   
Shouldn't this be automated in the database?
 
I mean in order to avoid two clients accessing the database at the same time?
 
In each query you can get it done properly, of course it can happen that you get empty numbers if one of the clients cancel the addition...
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Write a query to get the maximum id from the database e.g. select max(id) from invoicetable.
Store this result in a variable, increment it by 1, and then display it in the textbox.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 6

You can actually use this:
"cmd.CommandText = "Select Max (custno)+1 from [cust]"
 
It will select the maximum custno then it automatically incremented by 1.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

You could just use a query
 
SELECT MAX(invoiceNum) FROM Table
 
However, if you want uniqueness use a guid or some other scheme
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

  Permalink  
Comments
khaliloozx at 16-Jul-11 14:05pm
   
I think that i can easily search on google
thatraja at 16-Jul-11 14:29pm
   
Of course dude
aspnet_regiis at 7-Aug-12 10:45am
   
Yes that what we want.. Search on google, try to implement and come back only if you have specific problems...
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

I used this code
it's solved
 
<pre lang="vb">Private Sub auto()
        Dim cmd As New OleDbCommand
        cmd.CommandType = CommandType.Text
        cmd.Connection = conn
        cmd.CommandText = "Select Max (custno) from [cust]"
        conn.Open()
        Dim a As Integer = cmd.ExecuteScalar
        conn.Close()
        Custno.Text = a + 1
        If Custno.Text = "" Then
 
        End If
 
Thanks for all
  Permalink  
Comments
Dave Kreskowiak at 17-Jul-11 9:53am
   
Yeah, that's nice and all, but have you thought of the case where two clients running your code execute this at the same time?? Both clients are going to come up with the exact same "Customer Number".
aspnet_regiis at 7-Aug-12 10:46am
   
Dave is right..
tanugarg at 28-May-14 3:37am
   
this code helpful for me but i have one query that if database is not having value means column has null value this code give an error Conversion from type 'DBNull' to type 'Integer' is not valid
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 7

Don't generate the number in advance. More than one user will generate the same invoice number. Instead generate the Invoice number at the time of inserting the record into the database
 
INSERT INTO [cust](InVoiceNumber,..,..,..) values (SELECT Max (custno) from [cust],..,..,..)
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 467
1 CPallini 400
2 Sergey Alexandrovich Kryukov 348
3 BillWoodruff 254
4 George Jonsson 251
0 OriginalGriff 5,370
1 CPallini 4,360
2 Sergey Alexandrovich Kryukov 3,822
3 George Jonsson 3,037
4 Gihan Liyanage 2,435


Advertise | Privacy | Mobile
Web02 | 2.8.140916.1 | Last Updated 15 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100