Hi all webbers,
I have a problem of generating numbers automatically....
Actually i have a textbox and the textbox should autogenerate a number everytime the page loads or whenever the user clicks the next button after filling in the values.....

Help me out dudes.......Sample code would help me a lot.....

Recommended Answers

All 4 Replies

Can you describe the number? Something completely (pseudo)random? A unique ID? A sequence number? What you're using it for determines how you generate it.

I am using the numbers for serializing my datas..The numbers should generate automatically like 1 for the first record 2 for the second 3, 4 ,5 etc...But the number should continue even he logs out and logs in next time.The form contains Issue number, Name,Address,Issue Date etc...I want the issue number to get generated automatically.....I hope it clears ur question...!

I managed to generate the numbers,but i have a little problem.I have given this code in my page load event to fetch the last record from the database and increment the value of issue_no by one.It is incrementing the value but once i click the add button after filling other details,the next number is not getting incremented after the button click,any suggestion man....It is getting incremented after i sttoped and then running my program again....
I want the next no to be incremented so that the user can enter multiple datas without closing the application....

Con = new SqlConnection("Data Source=PSTLCORPSERV;Initial Catalog=Error;Persist Security Info=True;User ID=sa;Password=sqlserver12#");
            Cmd = new SqlCommand("select issue_no from error", Con);
            Data = Cmd.ExecuteReader();
            while (Data.Read() != false)

                auto = Data.GetString(0);	


                int newid = Int32.Parse(auto);
                int id = newid + 1;
                this.textBox1.Text = id.ToString() + "";

            catch (Exception ex)
                MessageBox.Show(ex.Message + ex.Source);


your code is true but did a little more.
make the procedure or function to generate auto number only. so you can call this procedure or function after you add,edit,delete or clear form.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.