要么你在sql语句中就加上选择
要么在已经存在的datatbale中用datatable的select方法选择

解决方案 »

  1.   

    请教下 ,这个用LINQ 可以实现吗?如何操作?
      

  2.   

    如果 table 的三列“姓名、检查项目、状态”都明确定义为string类型,可以这样写:var result = from DataRow row in table.Rows
                    group row by (string)row["姓名"] into g
                    where (from x in g
                        where ((string)x["检查项目"]).EndsWith("彩超")
                        select x).Any()
                    where !(from x in g
                            where (string)x["状态"] != "未检"
                            select x).Any()
                    select g.Key;
      

  3.   

    逻辑上很简单:
    1. group by,按照姓名分组,最终返回这个姓名。
    2. 第一个条件,判断至少有一个检查项目是以“彩超”两个字结束的。
    3. 第二个条件,判断所有的状态都不是“未检”。
      

  4.   


      var result = from DataRow row in table.Rows where (row.Field<string>("状态") == "未检" && row.Field<string>("姓名") == "李五" && row.Field<string>("检查项目").EndsWith("彩超")) select row;
      DataTable table1 = result.CopyToDataTable();
     dataGridView1.DataSource = table1;         
      

  5.   

    C#数据筛选问题
    //查询设置
    <asp:TextBox  CssClass="shenlan" ID="UserName" runat="server" Width="167px"></asp:TextBox>//查询用户
     <asp:RadioButtonList ID="cai_chao" runat="server" RepeatDirection="Horizontal"
                    Width="80px" Font-Size="12px">
                    <asp:ListItem Selected="True">彩超</asp:ListItem>
                    <asp:ListItem>非彩</asp:ListItem>
                </asp:RadioButtonList>//检测项目
     <asp:RadioButtonList ID="zh_tai" runat="server" RepeatDirection="Horizontal"
                    Width="80px" Font-Size="12px">
                    <asp:ListItem Selected="True">已捡</asp:ListItem>
                    <asp:ListItem>未捡</asp:ListItem>
                </asp:RadioButtonList>//状态
    <asp:Button ID="btnSearch" runat="server" Text="检索" OnClick="btnSearch_Click" />
    //处理搜索信息
     protected void btnSearch_Click(object sender, EventArgs e)
        {
            if (UserName.Text.Trim() != "")
            {
                Session["searchUserName"] = UserName.Text;
                Session["searchKey1"] = cai_chao.SelectedValue.Trim();
                Session["searchKey2"] = zh_tai.SelectedValue.Trim();
                Response.Redirect("Ssdiqu_nn.aspx");
            }
            else
            {
                Page.RegisterStartupScript("", "<script>alert('关键词不可以为空')</script>");
            }        }//codego.net/tags/1/1/
    //加载显示搜索页面信息
     protected void bindDataList()
        {        int noncePage = Convert.ToInt32(labPage.Text);
            PagedDataSource ps = new PagedDataSource();
            string sqlSel1 = "select * from tb_huen_lian where UserName like '%" + Session["searchUserName"] + "%'  and cai_chao like '%" + Session["searchKey1"] + "%' and zh_tai like '%" + Session["searchKey2"] + "%'";
            ps.DataSource = operateData.getRows(sqlSel1).DefaultView;
            ps.AllowPaging = true;
            ps.PageSize = 8;
            ps.CurrentPageIndex = noncePage - 1;
            this.lnkbtnFront.Enabled = true;
            this.lnkbtnNext.Enabled = true;
            this.lnkbtnLast.Enabled = true;
            this.lnkbtnFirst.Enabled = true;
            if (noncePage == 1)
            {
                this.lnkbtnFirst.Enabled = false;//不显示第一页按钮
                this.lnkbtnFront.Enabled = false;//不显示上一页按钮
            } if (noncePage == ps.PageCount)
            {
                this.lnkbtnNext.Enabled = false;//不显示下一页
                this.lnkbtnLast.Enabled = false;//不显示最后一页
            }
            labBackPage.Text = Convert.ToString(ps.PageCount);
            DataList1.DataSource = ps;
            DataList1.DataBind();    }
      

  6.   

    是数据库表的话一个SQL 就完了 
    在程序里的话 一个linq也同理