Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
im new in this world i want to generate serial no like 000001 to 000010 from user input when i click generate btn generate no in insert to datagridview and when i click save btn then save this datagridview data in table like id,barcodeNO,ColorName,size

1 000001 pink 39 2 000002 pink 40 3 000003 pink 41

im successful to generate range from user input with color and size now problem in generate only serial no.

here is my code

What I have tried:

C#
private void button1_Click(object sender, EventArgs e) {

for (int a = int.Parse(textBox1.Text); a < int.Parse(textBox2.Text);           a = a + 1)
        {
            int row=0;
            dataGridView1.Rows.Add();
            row=dataGridView1.Rows.Count -2;
            dataGridView1["color", row].Value = textBox3.Text;
            dataGridView1["Size", row].Value = a;
            //[enter image description here][1]dataGridView1["Barcode", row].Value = dt.ToString();

        }
    }
Posted
Updated 28-Dec-16 2:36am

1 solution

Don't.
Never try to "pregenerate" sequential numbers - only ever create them when you actually add data to the "backing storage" such as a database. (And all databases have a mechanism for creating them for you automatically at that point)
The user doesn't need it until it becomes "permanent" and having them displayed implies permanence. If you rely on it before that, then you can get enormous problems later when some values either don't get stored - because the user changed his mind for example - or get stored against the wrong ID value (because a different user also gets the same numbers).
 
Share this answer
 
Comments
Member 12861580 28-Dec-16 5:00am    
database max value 000009 store
now how can i generate number when user give pink color size 36 to 41 software generate Pink 36 000010
pink 37 000011
pink 38 000012
pink 39 000013
pink 40 000014
pink 41 000015
OriginalGriff 28-Dec-16 5:06am    
Don't. Let the DB handle that by making the serial number an IDENTITY field - the DB will then assign unique sequential numbers when you INSERT your rows.
Member 12861580 28-Dec-16 5:24am    
then how can i solve this problem sir?
OriginalGriff 28-Dec-16 5:26am    
Very simple: let the DB take care of it. Anything else is just asking for problems!
Member 12861580 28-Dec-16 5:58am    
can you please write example or code for me ?

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900