Click here to Skip to main content
15,884,176 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all, I wanna ask a question. I need to determine the maximum number of a certain field so that i can use that maximum number to automatically generate an ID with certain format.
Here is to explain in general about what i should do.

Table A:
Complaint ID
1
2
3
4
5

(I need to add the maximum number to generate an ID in a certain format such as Complaint ID max number + 1)

Table B:
FileID = 'AA' + (ComplaintID Max + 1)

I would appreciate 4 any response..thank you in advance
Posted

1 solution

This code is For auto generate ID

C#
public void generatecode()
        {
            int r;
            {
                sconn.Open();
                SqlCommand cmd = new SqlCommand("Select max(Voucher_No) from Front_Payment", sconn);
                SqlDataReader dr = cmd.ExecuteReader();
                if (dr.Read())
                {
                    string d = dr[0].ToString();
                    if (d == "")
                    {
                        txtvoucher.Text = "1";//set the value in textbox which name is id
                    }
                    else
                    {
                        r = Convert.ToInt32(dr[0].ToString());
                        r = r + 1;
                        txtvoucher.Text = r.ToString();
                    }
                }
                sconn.Close();
            }
        }
 
Share this answer
 

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