你是要做in操作吧,似乎不能直接传参,试一下这种http://bbs.csdn.net/topics/340060124
或者这种
string query = "19,21,24";
string[] param = query.Split(',');
string temp = "";
for (int i = 0; i < param.Length; i++)
{
temp += "@param" + i.ToString() + ",";
}
string queryString = "SELECT id,gender,name FROM [user] Where id in(" + temp.Substring(0, temp.Length - 1) + ")";
SqlCommand cmd = new SqlCommand(queryString, conn);
for (int i = 0; i < param.Length; i++)
{
cmd.Parameters.Add("@param" + i.ToString(), SqlDbType.Int).Value = param[i];
}
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
adapter.Fill(dt);
this.GridView1.DataSource = dt;
this.GridView1.DataBind();