private string getuniqueID() { con.OpenConnection(); int regcount = -1; string strregister = ""; string str = "select (MAX(SUBSTRING(Registration_Id,7,3))) from tbl_registration"; SqlCommand cmd = new SqlCommand(str, DBConnect.connection); SqlDataReader dr = null; try { dr = cmd.ExecuteReader(); if (dr.HasRows) { while (dr.Read()) { if (!(dr.GetValue(0).ToString() == "")) { regcount = Convert.ToInt32(dr.GetString(0)); int regcountinc = regcount + 1; if (regcountinc <= 9) { strregister = "STUREG00" + regcountinc; } else { strregister = "STUREG0" + regcountinc; } } else { strregister = "STUREG001"; } } } else { strregister = "STUREG001"; } txtregid.ReadOnly = true; } catch (SqlException ex) { MessageBox.Show(ex.Message); } finally { con.CloseConnection(); } return strregister;
var result = tbl_registration.Max(p => int.Parse(p.Registration_Id.Substring(7, 3)));
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)