Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
Hi
 
I need to generate and store Invoice Numbers like in the format 'E000001'
How to do it in VB.Net. Please help me with a code logic or suggest a better approach.
 
Thanks in anticipation
Sri
Posted 15-Jan-13 15:53pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Here's some C#, but the VB isn't much different.
 
string s = System.String.Format ( "E{0:000000}" , 42 ) ;
or
System.Console.WriteLine ( "E{0:000000}" , 42 ) ;
  Permalink  
Comments
cyanceenu at 16-Jan-13 2:34am
   
this is the thing I'm looking for.. thanks a lot..
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Sub generate_inv()
        Dim id_tmp As String
        Query = "select top 1 InoviceNo from Invoice order by InoviceNo desc"
        cmd = New OleDbCommand(query, cn)
        dr = cmd.ExecuteReader
        If dr.HasRows = False Then
            dr.Close()
            id_tmp = "E000001"
        Else
            dr.Read()
            id_tmp = Format(Mid(dr("InoviceNo"), 2, 6) + 1,"E00000#")
        End If
        dr.Close()
        txtInvoice.Text = id_tmp
End Sub
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

I wrote this in notepad so i have no idea if it will even compile but it should at least point you in right direction.
 
//No Database Approach
int seedNum = 1;
char pad = '0';
 
private void Main()
{
	for(int i=0; i < 10; i ++)
	{
		Console.WriteLine("E" + seedNum.ToString().padLeft(6,pad);
		seedNum += 1;
	}
}
 
private string GenerateInvNo()
{
	return seedNum.ToString().PadLeft(6, pad);
}
//-------------------------------------------------------
//Database Approach

string ConnectionString = String.Format(@"Data Source = {0};User Id={1}; password={2}; Initial Catalog = {3};",
                            "DB_Server",
                            "DB_User",
                            "DB_Pass",
                            "DB_Name");
 
string query = "SELECT SeedNumber FROM YourTableName; UPDATE YourTableName SET SeedNumber = SeedNumber + 1";
 
SqlConnection connection = new SqlConnection(ConnectionString);
connection.Open();
SqlCommand queryCMD = new SqlCommand(query, connection);
 
int seedNum = (int)queryCMD.ExecuteScalar();
char pad = '0';
 
Console.WriteLine("E" + seedNum.ToString().padLeft(6,pad);
  Permalink  
Comments
cyanceenu at 16-Jan-13 2:36am
   
It works fine.. though it didn't serves my purpose, but gave me some idea.. Thanks...

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 686
1 OriginalGriff 498
2 Tadit Dash 420
3 sanket saxena 337
4 Zoltán Zörgő 230
0 Sergey Alexandrovich Kryukov 11,800
1 OriginalGriff 7,225
2 Peter Leow 5,009
3 Abhinav S 3,893
4 Maciej Los 3,575


Advertise | Privacy | Mobile
Web03 | 2.8.140421.2 | Last Updated 16 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid