public List <QuestionMaster> GetByGroup(int GroupId, Connection con) { Command cmd = new Command(); string Query = @"SELECT * FROM Question_Master WHERE QuestionGroup=@QuestionGroup AND Active=1; SELECT * FROM Question_Options QO WHERE QO.Qid IN(SELECT Q.Qid FROM Question_Master Q WHERE QuestionGroup=@QuestionGroup and Q.Active=1) and QO.Active=1"; cmd.Parameters.Add("@QuestionGroup", DBType.Int, GroupId); cmd.CommandText = Query; cmd.CommandType = DBConnection.CommandType.Text; con.cmd = cmd; DataSet DS = con.getDataSet(); List <QuestionMaster> obj = new List <QuestionMaster>(); QuestionOptions q = new QuestionOptions(); List <QuestionOptions> op = q.GetData(DS.Tables[1]); foreach (DataRow DR in DS.Tables[0].Rows) { obj.Add(new QuestionMaster(DR, op.FindAll(r => r.Qid == (long)DR["Qid"]))); } return(obj); }