我想做一个搜索框,用户在框中输入内容,按确定后就把相应搜索结果显示在repeater里,下面是我写的代码,各位高手看看什么问题,指点啊···
        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["register"].ConnectionString);
        SqlCommand cmd = new SqlCommand();
        cmd.CommandText = "select * from aa where content like '%@content%'";
        cmd.Connection = con;
        cmd.Parameters.Add(new SqlParameter("@content", TextBox1.Text));
        SqlDataAdapter da = new SqlDataAdapter();
        da.SelectCommand = cmd;
        con.Open();
        DataSet ds = new DataSet();
        da.Fill(ds);
        con.Close();
        Repeater1.DataSource = ds;
        Repeater1.DataBind();我想问题就在于cmd.CommandText = "select * from aa where content like '%@content%'";这句,我试过cmd.CommandText = "select * from aa" 这样子是没有问题的,但我不知道怎么改。

解决方案 »

  1.   

    select * from aa where content like '%"+@content+"%'";
      

  2.   

     "select * from aa where content like '%"+content%+"'"; 
      

  3.   

    "select * from aa where content like '%"+@content+"%'"这样写的话就弹出
    编译器错误信息: CS0103: 当前上下文中不存在名称“content”不改前就没弹错误,但搜索不了···
      

  4.   

    cmd.CommandText = "select * from aa where [content] like %@content%"; 直接这样就可以了!
      

  5.   

    cmd.CommandText = "select * from aa where [content] like %@content%"; 
    这样的话,也有错误啊···
    第 1 行: '@content' 附近有语法错误。 
      

  6.   

    cmd.CommandText = "select * from aa where [content] like @content"; cmd.Parameters.Add(new SqlParameter("@content", "%"+TextBox1.Text+"%"));