/////////////////////////////////////////////////////////////////// // Copied from view.aspx.cs /////////////////////////////////////////////////////////////////// private void retrieve(string ID) { ClsUtil u = ClsUtil.Instance(); string strQuery = "SELECT * FROM [User] WHERE ID = " + ClsUtil.sqlEncode(ID); if (ClsUtil._DEBUG) { Response.Write(strQuery); } string strConn = u.strConn(); SqlConnection conn = null; try { conn = new SqlConnection(strConn); SqlCommand comm = new SqlCommand(strQuery, conn); conn.Open(); using (SqlDataReader sdr = comm.ExecuteReader()) { if (sdr.Read()) { this.first_name = ClsUtil.getStrVal(sdr["first_name"]); this.last_name = ClsUtil.getStrVal(sdr["last_name"]); this.email = ClsUtil.getStrVal(sdr["email"]); this.login = ClsUtil.getStrVal(sdr["login"]); this.note = ClsUtil.getStrVal(sdr["note"]); this.gid = ClsUtil.getStrVal(sdr["gid"]); //this.create_by = ClsUser.getUserNameById(ClsUtil.getStrVal(sdr["create_User_id"])); //this.create_datetime = ClsUtil.getStrVal(sdr["create_datetime"]); this.last_update_by = ClsUser.getUserNameById(ClsUtil.getStrVal(sdr["last_update_User_id"])); this.last_update_datetime = ClsUtil.getStrVal(sdr["last_update_datetime"]); this.disabled = ClsUtil.getStrVal(sdr["disabled"]); } } } catch (Exception ex) { throw new Exception(ex.Message); } finally { if (conn != null) { conn.Close(); } } }
public void retrieveDB(string ID) { this.clear(); this._strQuery = "SELECT * FROM [User] WHERE ID = " + ClsDB.sqlEncode(ID); DataTable dt = new ClsDB().ExecuteDataTable(this._strQuery); if (dt == null) { return; } if (dt.Rows.Count > 0) { DataRow sdr = dt.Rows[0]; this.first_name = ClsUtil.getStrVal(sdr["first_name"]); this.last_name = ClsUtil.getStrVal(sdr["last_name"]); this.email = ClsUtil.getStrVal(sdr["email"]); this.login = ClsUtil.getStrVal(sdr["login"]); this.note = ClsUtil.getStrVal(sdr["note"]); this.gid = ClsUtil.getStrVal(sdr["gid"]); this.create_by = ClsUser.getUserNameById(ClsUtil.getStrVal(sdr["create_User_id"])); this.create_datetime = ClsUtil.getStrVal(sdr["create_datetime"]); this.last_update_by = ClsUser.getUserNameById(ClsUtil.getStrVal(sdr["last_update_User_id"])); this.last_update_datetime = ClsUtil.getStrVal(sdr["last_update_datetime"]); this.disabled = ClsUtil.getStrVal(sdr["disabled"]); } /* * Get same result as above code. * * ClsUtil u = ClsUtil.Instance(); * string strConn = u.strConn(); * SqlConnection conn = null; * * try * { * conn = new SqlConnection(strConn); * SqlCommand comm = new SqlCommand(strQuery, conn); * * conn.Open(); * using (SqlDataReader sdr = comm.ExecuteReader()) * { * if (sdr.Read()) * { * this.first_name = ClsUtil.getStrVal(sdr["first_name"]); * this.last_name = ClsUtil.getStrVal(sdr["last_name"]); * this.email = ClsUtil.getStrVal(sdr["email"]); * this.login = ClsUtil.getStrVal(sdr["login"]); * this.note = ClsUtil.getStrVal(sdr["note"]); * this.gid = ClsUtil.getStrVal(sdr["gid"]); * * this.create_by = ClsUser.getUserNameById(ClsUtil.getStrVal(sdr["create_User_id"])); * this.create_datetime = ClsUtil.getStrVal(sdr["create_datetime"]); * this.last_update_by = ClsUser.getUserNameById(ClsUtil.getStrVal(sdr["last_update_User_id"])); * this.last_update_datetime = ClsUtil.getStrVal(sdr["last_update_datetime"]); * this.disabled = ClsUtil.getStrVal(sdr["disabled"]); * } * } * } * catch (Exception ex) * { * throw new Exception(ex.Message); * } * finally * { * if (conn != null) conn.Close(); * } */ }