微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

我如何按日期从控制器过滤重复数据以查看使用Sql查询

如何解决我如何按日期从控制器过滤重复数据以查看使用Sql查询

我正在使用SQL查询

This is my description on the sql server I want to apply to the program with little change

我尝试了此代码,但失败了

这是控制器代码

        public ActionResult xternal(string Datecall)
        {
            DataTable dt = new DataTable();
            string str = "Data Source=MAHGOUBND4;Initial Catalog=CTC_Mahgoub;Persist Security Info=True;User ID=sa;Password=ah987987987;";
            using (sqlConnection cn = new sqlConnection(str))
            {
                using (sqlCommand cmd = new sqlCommand(" SELECT EmployeeName,COUNT(EmployeeName) as 'Duplecated'  FROM [dbo].[cs] WHERE Datecall LIKE '%" +Datecall.Tostring()+ "%' GROUP BY EmployeeName HAVING COUNT(EmployeeName) > 1; "))
                {
                    cmd.Connection = cn;
                    using (sqlDataAdapter da = new sqlDataAdapter(cmd))
                    {
                        da.Fill(dt);
                    }
                }
            }
            return View(dt);
        }

这是我的查看代码

我的代码有问题,我想补偿文本Datecall中的数据表值Datecall我该怎么做

这是查看代码

@using System.Data
@model DataTable

<input type="text" name="date" id="Datecall" placeholder="Date" required="" />

<input type="button" id="btnsearch" name="btnsearch" value="Chart" style="color:green" />

<table cellpadding="5" id="employeeTable" cellspacing="5" border="1">
    <tr style="background-color:aliceblue">
        <th>EmployeeName</th>
        <th>Duplecated</th>
    </tr>
    @foreach (DaTarow dr in Model.Rows)
    {
        <tr>
            <td>@dr["EmployeeName"]</td>
            <td>@dr["Duplecated"]</td>
        </tr>
    }
</table>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。