You need to parse you
StudId
because is it string
try like this
private void GenerateID()
{
con.Open();
cmd = new MySqlCommand("Select Max(StudID) from student_registration", con);
dr = cmd.ExecuteReader();
string newId = string.Format("050-{0}-0001", DateTime.Now.Year);
if (dr.HasRows)
{
string prefix = string.Format("050-{0}", DateTime.Now.Year);
while (dr.Read())
{
string maxId= dr[0].ToString();
if (!string.IsNullOrWhiteSpace(maxId) && maxId.StartsWith(prefix))
{
int count = Convert.ToInt32(maxId.Split('-')[2]);
newId = string.Format("050-{0}-{1:0000}", DateTime.Now.Year, count+1);
}
}
}
txtStudID.Text = newId;
con.Close();
}