SqlCommand myCommand = new SqlCommand("select id from b2cuser where sitedomain='12312'", myConnection);//原语句
我要把where后面的做成参数@sqlwhere
写成这样
  sqlwhere = "sitedomain='12312'";
  SqlCommand myCommand = new SqlCommand("select id from b2cuser where @sqlwhere", myConnection);
  myCommand.Parameters.Add(new SqlParameter("@sqlwhere",sqlwhere));]]
执行的时候不对.问下怎么改

解决方案 »

  1.   

    这样不行,估计你想这样where后全部构造,只能通过拼sql语句了
      

  2.   

    myCommand.Parameters.Add(new SqlParameter("@sqlwhere",sqldbtype.varchar,50));
    myCommand.Parameters["@sqlwhere"]=sqlwhere;
      

  3.   

    sqlwhere = "sitedomain='12312'";
    SqlCommand myCommand = new SqlCommand("select id from b2cuser where @sqlwhere", myConnection);
    myCommand.Parameters.Add("@sqlwhere",SqlDbType.VarChar);
    myCommand.Parameters["@sqlwhere"].Value = sqlWhere;
      

  4.   

    sqlwhere = "12312";
      SqlCommand myCommand = new SqlCommand("select id from b2cuser where sitedomain=@sqlwhere", myConnection);
      myCommand.Parameters.Add(new SqlParameter("@sqlwhere",sqlwhere));
      

  5.   

    你写个存储过程
    create procedure SelectCmd(@tiaojian varchar(100))
    as 
    begin
    exec('select id from b2cuser where '+@tiaojian)
    end
    然后执行这个存储过程,不知道可以不
      

  6.   

      sqlwhere = "'12312'";
      SqlCommand myCommand = new SqlCommand("select id from b2cuser where @sqlwhere", myConnection);
      myCommand.Parameters.AddWithValue(new SqlParameter("@sqlwhere",sqlwhere));]]
      

  7.   

    上面的写错了应该是
      sqlwhere = "'12312'"; 
      SqlCommand myCommand = new SqlCommand("select id from b2cuser where sqlwhere=@sqlwhere", myConnection); 
      myCommand.Parameters.AddWithValue("@sqlwhere",sqlwhere);