我这么写错了:
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["con"].ToString());
        SqlDataAdapter sda = new SqlDataAdapter("select * from article where classId in(@classId)",con);
        SqlParameter p1 = new SqlParameter("@classId", SqlDbType.Int);
        p1.Value = "135,22";
        sda.SelectCommand.Parameters.Add(p1);
        DataTable dt = new DataTable();
        sda.Fill(dt);
        Response.Write(dt.Rows.Count);

解决方案 »

  1.   

    SqlDbType.Int  ->   "135,22"
      

  2.   

    select * from article where charindex(','+classId+',',','+@classId+',')>0
      

  3.   

    ??  我数据库里的classid是int
      

  4.   

    SqlParameter p1 = new SqlParameter("@classId", SqlDbType.Int);
    --->
    SqlParameter p1 = new SqlParameter("@classId", SqlDbType.Nvarchar);
    试试
      

  5.   

    SqlDataAdapter sda = new SqlDataAdapter(String.Format("select * from article where classId in({0})","135,22"),con);
      
    *****************************************************************************
    欢迎使用CSDN论坛阅读器 : CSDN Reader(附全部源代码) 
    http://www.cnblogs.com/feiyun0112/archive/2006/09/20/509783.html
      

  6.   

    晕了,  
    p1.Value = "135,22";
    这里还是数值行啊,怎么赋值啊,属性不对啊,
    前面
    SqlParameter p1 = new SqlParameter("@classId", SqlDbType.Int);
    这里试试换上字符串
    SqlParameter p1 = new SqlParameter("@classId", SqlDbType.String);
      

  7.   

    SqlDbType中没有string那个属性  我数据库中的classid是int
      

  8.   

    使用下面的方法可以实现:
    SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["con"].ToString());
    string Sql = "select * from article where classId in(@classId)";        Sql = Sql.Replace("(@classId","135,22");
            SqlDataAdapter sda = new SqlDataAdapter(Sql,con);
            DataTable dt = new DataTable();
            sda.Fill(dt);
            Response.Write(dt.Rows.Count);
      

  9.   

    如果你"135,22"这个值是是由一个int[]数组传参过来的,那他们怎么注入啊.int类型的只能是数字
    你完全可以拼成一个SQL语句的咯.
      

  10.   

    pyuan(菜鸟) 
    讲得有道理。
      

  11.   

    SqlDataAdapter sda = new SqlDataAdapter("select * from article where classId in(@classId)",con);
            SqlParameter p1 = new SqlParameter("@classId", SqlDbType.VarChar);
            p1.Value = "‘135’,‘22’";
      

  12.   

    我数据库中真正的类型是int,我用循环也能实现带参数  就是麻烦点数值转数字,字符串过滤引号真的就可以了吗?  (但是我需要用引号所以引号不能过滤!!)所以才需要带参数执行!
      

  13.   

    "135,22" 这是一个字符串。
    不是一个 int 值,你把一个字符串赋给一个int型,不出错就是没天理了。
      

  14.   

    试试这样
      ……
      SqlDataAdapter sda = new SqlDataAdapter("select * from article where classId in(@classId1,@classId2,@classId3……)",con);  SqlParameter p1 = new SqlParameter("@classId1", SqlDbType.Int);
      p1.Value = 135; //或int变量
      sda.SelectCommand.Parameters.Add(p1);  SqlParameter p2 = new SqlParameter("@classId2", SqlDbType.Int);
      p2.Value = 22; //或int变量
      sda.SelectCommand.Parameters.Add(p2);  SqlParameter p3 = new SqlParameter("@classId3", SqlDbType.Int);
      p3.Value = 33; //或int变量
      sda.SelectCommand.Parameters.Add(p3);  ……PS:直接连接字符串不更简单吗?遇到这种情况非要用Parameter,岂不是将简单问题变复杂了?呵呵
      

  15.   

    string sql = "declare @sql nvarchar(3000) set @sql=' select * from article where classId in (";
    sql + = your nid string + ")' exec @sql"