??????????СС??????????????????в????????????where in??like???????????????????????????????????μ??????????????????????????SQL????в??????????????????????????SQL?????????????????where in ?????????????????????????????????????????????е?????????????where in??like????????????????ò?????????????

????where in ?????????????

???????????????????????????SQL????????????????????????

string userIds = "1??2??3??4";
using (SqlConnection conn = new SqlConnection(connectionString))
{
  conn.Open();
  SqlCommand comm = new SqlCommand();
  comm.Connection = conn;
  comm.CommandText = string.Format("select * from Users(nolock) where UserID in({0})"?? userIds);
  comm.ExecuteNonQuery();
}

????????????????????е?????????????????????SQL???????

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

?????????????????????? varchar ? '1??2??3??4' ????????????? int ????????????????????????where in????@UserID??????????????????????????????????????

select * from Users(nolock) where UserID in('1??2??3??4')

????????е????????????????SQL??в???????????????????κν????

using (SqlConnection conn = new SqlConnection(connectionString))
{
  conn.Open();
  SqlCommand comm = new SqlCommand();
  comm.Connection = conn;
  comm.CommandText = "select * from Users(nolock) where UserName in(@UserName)";
  comm.Parameters.Add(new SqlParameter("@UserName"?? SqlDbType.VarChar?? -1) { Value = "'john'??'dudu'??'rabbit'" });
  comm.ExecuteNonQuery();
}

?????????????κδ?????鯔?????????????????@UserName??????????????????????????????????????

select * from Users(nolock) where UserName in('''john''??''dudu''??''rabbit''')

????????????????????μ???where in ?????????????????????????????????????????????????????????????where in?????????????????where in ???Σ???????????????????????

????????1?????CHARINDEX??like ??????????????????????????????????????????????????????????????????????ò???????Ч????????????????????????????????裬???????????????????????????????????????д?????????????????????????????С???????????????????SQL?????????д??????????????????????????????

using (SqlConnection conn = new SqlConnection(connectionString))
{
  conn.Open();
  SqlCommand comm = new SqlCommand();
  comm.Connection = conn;
  //???CHARINDEX?????????????????????ò?????????????????Ч
  comm.CommandText = "select * from Users(nolock) where CHARINDEX('??'+ltrim(str(UserID))+'??'??'??'+@UserID+'??')>0";
  comm.Parameters.Add(new SqlParameter("@UserID"?? SqlDbType.VarChar?? -1) { Value = "1??2??3??4" });
  comm.ExecuteNonQuery();
}
using (SqlConnection conn = new SqlConnection(connectionString))
{
  conn.Open();
  SqlCommand comm = new SqlCommand();
  comm.Connection = conn;
  //???like?????????????????????ò?????????????????Ч
  comm.CommandText = "select * from Users(nolock) where '??'+@UserID+'??' like '%??'+ltrim(str(UserID))+'??%' ";
  comm.Parameters.Add(new SqlParameter("@UserID"?? SqlDbType.VarChar?? -1) { Value = "1??2??3??4" });
  comm.ExecuteNonQuery();
}