Q:

Converting a string (p01..p02..p03) to a string/int?

Im new to programming.. I need to convert a string of patients from the database as p01 p02 p03... to create a newid when I enter a new patient into the database. I currently have this code but I have done it wrong.. any help would be appreciated! Thanks
public void patientInsert()         
{
        hospitalSQLEntities db = new hospitalSQLEntities();
        int newid = 0;
    if (db.patients.Count() ==0)
          newid = 1; 
else
newid = db.patients.Max(u => u.PatientID) + 1;
...

A:

You should let the DB assign the primary key. Most commonly the primary key is an integer and marked as IDENTITY and automatically assigned by the database when you insert a row into the table.
For SQL server you can designate the primary key to be Identity in SQL Server Management Studio:

