????????2?????exec??????SQL????????д?????????????????????????????????????????SQL??????????????????????????????д????????SQL???????????????????????е?????????????????????κ???????????????????????о??????????????????????????????

using (SqlConnection conn = new SqlConnection(connectionString))
{
  conn.Open();
  SqlCommand comm = new SqlCommand();
  comm.Connection = conn;
  //???exec??????SQL????//?????е???????(@UserID varchar(max))select * from Users(nolock) where UserID in (1??2??3??4)????//????????(@UserID varchar(max))exec('select * from Users(nolock) where UserID in ('+@UserID+')') comm.CommandText = "exec('select * from Users(nolock) where UserID in ('+@UserID+')')";
  comm.Parameters.Add(new SqlParameter("@UserID"?? SqlDbType.VarChar?? -1) { Value = "1??2??3??4" });
  comm.ExecuteNonQuery();
}

????????3???where in???????????????????????д???????鷳Щ???????????????????????2100??????????????????????????????

using (SqlConnection conn = new SqlConnection(connectionString))
{
  conn.Open();
  SqlCommand comm = new SqlCommand();
  comm.Connection = conn;
  //???????????????????
  comm.CommandText = "select * from Users(nolock) where UserID in (@UserID1??@UserId2??@UserID3??@UserID4)";
  comm.Parameters.AddRange(
  new SqlParameter[]
  {
    new SqlParameter("@UserID1"?? SqlDbType.Int) { Value = 1}??
    new SqlParameter("@UserID2"?? SqlDbType.Int) { Value = 2}??
    new SqlParameter("@UserID3"?? SqlDbType.Int) { Value = 3}??
    new SqlParameter("@UserID4"?? SqlDbType.Int) { Value = 4}
  });
  comm.ExecuteNonQuery();
}

????????4??????????????д????????????Щ????????????д??????where in??????????????????????裬?????????????д??????????????????????????????????Ч??????????????????????????????????????IO??????????????????ε??????????????????÷???3???????????????????????????????????????????????????????????????????????????????????????

using (SqlConnection conn = new SqlConnection(connectionString))
{
  conn.Open();
  SqlCommand comm = new SqlCommand();
  comm.Connection = conn;
  string sql = @"
  declare @Temp_Variable varchar(max)
  create table #Temp_Table(Item varchar(max))
  while(LEN(@Temp_Array) > 0)
  begin
  if(CHARINDEX('??'??@Temp_Array) = 0)
  begin
  set @Temp_Variable = @Temp_Array
  set @Temp_Array = ''
  end
  else
  begin
  set @Temp_Variable = LEFT(@Temp_Array??CHARINDEX('??'??@Temp_Array)-1)
  set @Temp_Array = RIGHT(@Temp_Array??LEN(@Temp_Array)-LEN(@Temp_Variable)-1)
  end
  insert into #Temp_Table(Item) values(@Temp_Variable)
  end
  select * from Users(nolock) where exists(select 1 from #Temp_Table(nolock) where #Temp_Table.Item=Users.UserID)
  drop table #Temp_Table";
  comm.CommandText = sql;
  comm.Parameters.Add(new SqlParameter("@Temp_Array"?? SqlDbType.VarChar?? -1) { Value = "1??2??3??4" });
  comm.ExecuteNonQuery();
}