AspdotnetCodes.com
Search
Articles
Books
Resources
Asp.Net News
Downloads
Free Tech Magazines
Asp.Net Web Hosting
Archives
Softwares
Newsletter
Suggest Us
Link to Us
Feeds Subscription
Articles
Questions & Answers
Tips & Tricks
 Kevin's CodeGenerator (Free)
Post New Projects
 
Kevin’s Code Generator is an asp.net Class Library Component used to generate unique codes. Instead of using identity column as primary key, there are many circumstances where we need to generate unique integer sequence numbers, alpha numeric codes, random codes, etc,. Kevin’s Code Generator helps us to achieve this. Ease of use and flexibility makes Kevin’s Code Generator more prominent. Through this component you can create four types of codes to be used in your application. You can create unique integer codes, alpha-numeric codes and one step further this component provides a method to create random codes (beta).
Let us see how to implement this component in our projects. Download the zip file and unzip it in your local drive. You can find CodeGenerator.dll in it. In your Visual Studio 2005 solution explorer, right click on the bin folder and click Add Reference. Browse the location of the dll. Now you can see the CodeGenerator.dll under your bin folder. Now go to your code-behind file, add reference as ‘Using CodeGenerator;’ and create an object for the CodeGenerator class as follows

CodeGenerator cg = new CodeGenerator();

Then you have to set the ConnectionString property to locate your database. That’s it. You can use all the four methods available in the component.

The first method is GetUniqueIntegerCode used to generate Integer code. Arguments are TableName, FieldName and Initial value. The syntax for this method

String Code=cg.GetUniqueIntegerCode("<yourtablename>","<fieldname>","InitialValue");


The second method GetUniqueStringCode generates sequence of Alpha-numeric codes. You can create n-digits of alpha-numeric codes through this method.

String Code=cg.GetUniqueStringCode("<YouTableName>","<FieldName>","Starting Alphabet",Length in Integer) ;


FYI: Length is how many numbers of digits you need after the starting alphabet. That is, if your Field length is 4, then your starting alphabet is ‘A’ and you need 3 digits of numbers. So it Length as 3.

The third method GetUniqueMixedStringCode is used to generate unique mixed string codes. For example, if your table’s primary key need to have different types of unique alpha-numeric sequence of codes like A01, A02, B01, B02, B03, C01…., you can use this method. You can create n-digits of alpha-numeric codes.

String Code=cg.GetUniqueStringCode("<YourTableName>","<FieldName>","Starting Alphabet",Length in Integer) ;

Example:
Code=cg.GetUniqueMixedStringCode("MyTable", "MyCodeField”, "AA", 5);
Code=cg.GetUniqueMixedStringCode("MyTable", "MyCodeField", "BB", 5);

The last method GetUniqueRandomCode, is still in its beta. It helps you to generate unique random codes from the specified table. Kevin recommends you to use this only if you need to generate 3 to 7 digits of random numbers. The syntax is

String Code=cg.GetUniqueRandomCode("<YourTableName>", "FieldName", Length in integer);


You can download this component for free from AspdotnetCodes.com. If you need further information regarding this component or in case you need the source code for further upgrading, please contact us through our Contact us page.

You need to Login or Register to download this component.
Sponsored by
The Art & Science of JavaScript - Free 100 Page Preview!
When Good HTML Goes Bad: How You Can Protect Your Web Applications
Windows 8: 50 Questions and Answers You Need to Make a Decision (Normally $9.95)