protected void Button1_Click(object sender, EventArgs e)
    {
        if (TextBox3.Text != "")
        {
            string sSql = "select * from Goods where title like '%" + TextBox3.Text + "%'and actor like '%" + TextBox3.Text + "%'";
            SQL s = new SQL();
            DataSet ds = s.DSSearch(sSql);// s.DSSearch(sSql);
            PagedDataSource pds = new PagedDataSource();//初始化PagedDataSource实例,主要用做DataList1的分页使用
            pds.AllowPaging = true;//允许分页
            pds.PageSize = 15;//每页显示10条
            pds.DataSource = ds.Tables[0].DefaultView;//将检索出的ds数据集绑定给PagedDataSource实例pds            DataList2.DataSource = pds;//将pds内容最终绑定给DataList1,呈现到界面中
            DataList2.DataBind();
        }
    }红字部分写了title和actor两个关键字搜索,可是运行的时候两个关键字都查询不到。如果只写一个title或者actor就可以查询出来没有显示代码错误。SQLC#搜索

解决方案 »

  1.   

    调试的时候可以将sql语句取出来 单独执行一下 很容易看出问题的
    目测and前面应该留空格 可以试一下
      

  2.   

     注意空格
    string sSql = "select * from Goods where title like '%" + TextBox3.Text + "%' and actor like '%" + TextBox3.Text + "%'";
      

  3.   

    string sSql = "select * from Goods where (title like '%" + TextBox3.Text + "%' ) or (actor like '%" + TextBox3.Text + "%')";
    你换用 or 试试
      

  4.   

    你用的 and 肯定找不到啦  要用 or  楼上正解啦
      

  5.   


    同意2l应该是空格问题吧。 and 前面应该有个空格吧
      

  6.   

    跟空格没关系(SQL Server 2005测了)。
    感觉是没有同时满足两个条件的数据。
    建议楼主做个测试,先确保有同时满足两个条件的数据,再测测这段SQL是否能查出数据。