private DataTable MakeExportID(DataTable dtViewName) { //--- make query using all viewname , execute the query to get distinct ptn_pk and store them in table dtViewPtnPk IExport ExportManager = (IExport)ObjectFactory.CreateInstance("BusinessProcess.Administration.BExport, BusinessProcess.Administration"); string theQuery = ""; int r = 0; foreach (DataRow theDRV in dtViewName.Rows) { if (theDRV["Ptn_Pk"].ToString() == "T") { if (r == 0) { theQuery = "SELECT DISTINCT " + theDRV["ViewName"] + ".Ptn_Pk" + " FROM " + theDRV["ViewName"]; } else if (theQuery.ToString() != "") { theQuery = theQuery + " UNION " + " SELECT DISTINCT " + theDRV["ViewName"] + ".Ptn_Pk" + " FROM " + theDRV["ViewName"]; } else { theQuery = " SELECT DISTINCT " + theDRV["ViewName"] + ".Ptn_Pk" + " FROM " + theDRV["ViewName"]; } } r = 1; } theQuery = theQuery + " ORDER BY Ptn_Pk"; DataTable dtViewPtnPk = new DataTable(); dtViewPtnPk = ExportManager.RunQuery(theQuery); string Ptn_Pk_List = ""; foreach (DataRow theDR in dtViewPtnPk.Rows) { if (Ptn_Pk_List == "") { Ptn_Pk_List = Ptn_Pk_List + theDR["Ptn_Pk"].ToString(); } else { Ptn_Pk_List = Ptn_Pk_List + "," + theDR["Ptn_Pk"].ToString(); } } dtViewPtnPk = null; DataTable dtPtnPkExport = new DataTable(); if (Ptn_Pk_List != "") { dtPtnPkExport = ExportManager.MakeExportID(Ptn_Pk_List); } return(dtPtnPkExport); }