Prince Cabanducos

Prince Cabanducos

  • NA
  • 33
  • 9.3k

How to concatinate customize primary ID every new entry.

Oct 21 2018 1:08 AM
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 in this case to SY18-19 so I can enter another shool year or everytime the form loads.
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.
My table structure is:
schoolyear_id -> as the primary key
schoolyear -> e.g. 2018-2019
status -> Active / Inactive

Answers (1)