У меня есть одна страница для удаления дубликатов, и она получает все значения дубликатов из 4 таблиц.теперь для привязки вида сетки я использую ту же настройку для связанного имени столбца.но он получил бы только первый результат запроса.
вот мой результат в SQL Server Management Studio:
и вот мой код:
string str = "";
DataTable dt = new DataTable();
str += "(SELECT ";
str += "s.Id, s.EmailAddress As ColumnValue,";
str += "(SELECT Name FROM tbl_User_master ";
str += "WHERE Id = s.user_id) AS CreatedBy,";
str += "d.Count ";
str += "FROM ";
str += "(SELECT EmailAddress, COUNT(*) as Count ";
str += "FROM tbl_Subscribers ";
str += "WHERE user_id = '1' ";
str += "GROUP BY EmailAddress ";
str += "HAVING COUNT(*) > 1) AS d ";
str += "INNER JOIN ";
str += "tbl_Subscribers s ON s.EmailAddress = d.EmailAddress)";
str += "(SELECT ";
str += "f.Id,f.EmailAddress As ColumnValue,";
str += "(SELECT Name FROM tbl_User_master WHERE Id = f.user_id) AS CreatedBy,";
str += "d.Count ";
str += "FROM ";
str += "(SELECT EmailAddress, COUNT(*) AS Count ";
str += "FROM tbl_From_master ";
str += "WHERE user_id = '1' ";
str += "GROUP BY EmailAddress ";
str += "HAVING COUNT(*) > 1) AS d ";
str += "INNER JOIN ";
str += "tbl_From_master f ON f.EmailAddress = d.EmailAddress)";
str += "(SELECT ";
str += "c.Id,c.CategoryName As ColumnValue,(SELECT Name FROM tbl_User_master WHERE Id = c.user_id) As CreatedBy, d.Count ";
str += "FROM (";
str += "SELECT CategoryName, COUNT(*) as Count ";
str += "FROM tbl_Categories WHERE user_id='1' ";
str += "GROUP BY CategoryName ";
str += "HAVING COUNT(*) > 1";
str += ") AS d ";
str += "INNER JOIN tbl_Categories c ON c.CategoryName = d.CategoryName)";
str += "(SELECT ";
str += "t.Id,t.CategoryName As ColumnValue,(SELECT Name FROM tbl_User_master WHERE Id = t.user_id) As CreatedBy, d.Count ";
str += "FROM (";
str += "SELECT CategoryName, COUNT(*) as Count ";
str += "FROM tbl_Template_Categories WHERE user_id='1' ";
str += "GROUP BY CategoryName ";
str += "HAVING COUNT(*) > 1";
str += ") AS d ";
str += "INNER JOIN tbl_Template_Categories t ON t.CategoryName = d.CategoryName)";
str += "(SELECT ";
str += "t.Id,t.TemplateName As ColumnValue,(SELECT Name FROM tbl_User_master WHERE Id = t.user_id) As CreatedBy,d.Count ";
str += "FROM (";
str += "SELECT TemplateName, COUNT(*) as Count ";
str += "FROM tbl_Template_master WHERE user_id='1' ";
str += "GROUP BY TemplateName ";
str += "HAVING COUNT(*) > 1";
str += ") AS d";
str += " INNER JOIN tbl_Template_master t ON t.TemplateName = d.TemplateName)";
dt = obj.Get_Data_Table_From_Str(str);
egrd.DataSource = dt;
egrd.DataBind();
ViewState["data"] = dt;
, но все равно возвращает только первый запросрезультат:
здесь я включаю мою разметку вида сетки:
<asp:GridView ID="egrd" runat="server" AutoGenerateColumns="true" CssClass="table table-striped table-bordered table-hover"
Width="100%" PageSize="9999999" HeaderStyle-CssClass="theme-font" OnPreRender="egrd_PreRender">
<EmptyDataTemplate>
<asp:Label ID="lblEmptySearch" runat="server" Font-Bold="true" ForeColor="Red">No Data Found To Display . . .</asp:Label>
</EmptyDataTemplate>
<Columns>
</Columns>
<HeaderStyle CssClass="theme-font"></HeaderStyle>
<RowStyle Wrap="False" />
</asp:GridView>
как мне решить эту задачу, пожалуйста, помогите мне ...
----------------------- Обновлено ---------------------------
хорошо, я сделал с этим:
if (groupByTable == 0)
{
str += "(SELECT ";
str += "s.Id, s.EmailAddress As ColumnValue,";
str += "(SELECT Name FROM tbl_User_master ";
str += "WHERE Id = s.user_id) AS CreatedBy,";
str += "s.SubscriptionDateTime As CreatedDate,d.Count ";
str += "FROM ";
str += "(SELECT EmailAddress, COUNT(*) as Count ";
str += "FROM tbl_Subscribers ";
str += "WHERE user_id = '" + int.Parse(CommonLogic.GetSessionValue("user_id").ToString()) + "' ";
str += "GROUP BY EmailAddress ";
str += "HAVING COUNT(*) > 1) AS d ";
str += "INNER JOIN ";
str += "tbl_Subscribers s ON s.EmailAddress = d.EmailAddress)";
str += " UNION ALL ";
str += "(SELECT ";
str += "f.Id,f.EmailAddress As ColumnValue,";
str += "(SELECT Name FROM tbl_User_master WHERE Id = f.user_id) AS CreatedBy,";
str += "f.CreatedDate As CreatedDate,d.Count ";
str += "FROM ";
str += "(SELECT EmailAddress, COUNT(*) AS Count ";
str += "FROM tbl_From_master ";
str += "WHERE user_id = '" + int.Parse(CommonLogic.GetSessionValue("user_id").ToString()) + "' ";
str += "GROUP BY EmailAddress ";
str += "HAVING COUNT(*) > 1) AS d ";
str += "INNER JOIN ";
str += "tbl_From_master f ON f.EmailAddress = d.EmailAddress)";
str += " UNION ALL ";
str += "(SELECT ";
str += "c.Id,c.CategoryName As ColumnValue,(SELECT Name FROM tbl_User_master WHERE Id = c.user_id) As CreatedBy,NULL As CreatedDate,d.Count ";
str += "FROM (";
str += "SELECT CategoryName, COUNT(*) as Count ";
str += "FROM tbl_Categories WHERE user_id='" + int.Parse(CommonLogic.GetSessionValue("user_id").ToString()) + "' ";
str += "GROUP BY CategoryName ";
str += "HAVING COUNT(*) > 1";
str += ") AS d ";
str += "INNER JOIN tbl_Categories c ON c.CategoryName = d.CategoryName)";
str += " UNION ALL ";
str += "(SELECT ";
str += "t.Id,t.CategoryName As ColumnValue,(SELECT Name FROM tbl_User_master WHERE Id = t.user_id) As CreatedBy,NULL As CreatedDate,d.Count ";
str += "FROM (";
str += "SELECT CategoryName, COUNT(*) as Count ";
str += "FROM tbl_Template_Categories WHERE user_id='" + int.Parse(CommonLogic.GetSessionValue("user_id").ToString()) + "' ";
str += "GROUP BY CategoryName ";
str += "HAVING COUNT(*) > 1";
str += ") AS d ";
str += "INNER JOIN tbl_Template_Categories t ON t.CategoryName = d.CategoryName)";
str += " UNION ALL ";
str += "(SELECT ";
str += "t.Id,t.TemplateName As ColumnValue,(SELECT Name FROM tbl_User_master WHERE Id = t.user_id) As CreatedBy,t.Created_date As CreatedDate,d.Count ";
str += "FROM (";
str += "SELECT TemplateName, COUNT(*) as Count ";
str += "FROM tbl_Template_master WHERE user_id='" + int.Parse(CommonLogic.GetSessionValue("user_id").ToString()) + "' ";
str += "GROUP BY TemplateName ";
str += "HAVING COUNT(*) > 1";
str += ") AS d";
str += " INNER JOIN tbl_Template_master t ON t.TemplateName = d.TemplateName)";
}