Thursday, August 13, 2009

Style Of C# Coding

Example Style if you have a long sql.

Not cool. Harder To see. Makes our head goes vertigo.

string selectSql = "SELECT MMIS_Login.uid, "MMIS_Personnel.person_id, MMIS_Personnel.first_name, MMIS_Personnel.last_name, MMIS_Personnel.division_id, MMIS_Login.email FROM MIS_Personnel INNER JOIN MMIS_Login ON MMIS_Personnel.person_id = MIS_Login.person_id WHERE (MMIS_Login.uid ='" + uid + "')";

Below is a right way.

string selectSql = "SELECT MMIS_Login.uid, " +
                   "MMIS_Personnel.person_id, " +
                   "MMIS_Personnel.first_name, " +
                   "MMIS_Personnel.last_name, " +
                   "MMIS_Personnel.division_id, " +
                   "MMIS_Login.email FROM MMIS_Personnel INNER JOIN " +
                   "MMIS_Login ON MMIS_Personnel.person_id = MIS_Login.person_id " +
                   "WHERE (MMIS_Login.uid ='" + uid + "')";

No comments:

Post a Comment