Prince Cabanducos

Prince Cabanducos

  • NA
  • 33
  • 9.4k

How to concatinate customize primary ID every new entry.

Oct 12 2018 11:25 PM
Hi everyone,

Can someone help me please. I have a program wherein a user can enter multiple entries to the database. The user will enter school years for which the primary ID is in 'SYyy-yy' format e.g. SY17-18, SY18-20 and so on. So everytime I enter a new entry, the program should read the last record on the table and concatinate it so that it wouldn't duplicate.
For example: My first entry has a primary ID of SY17-18 and it's schoolyear name is 2017-2018. The program should automatically concatinate the previous ID to SY18-19 so I can enter another shool year.
Does that make sense?

Hoping for any help, thank you.
 

PS: My current block of code is based on DateTime.Now as follows:

int curr = Convert.ToInt32(DateTime.Now.ToString("yy"));
int dt = curr + 1;
string sy = "SY" + curr.ToString() + "-" + dt.ToString();
txtSYID.Text = sy;

My problem to this is, the primary ID would duplicate since it is based on the DateTime.Now and I can only enter 1 record.

Answers (2)