Quote:
textbox have values 1002,1991,2007,3006
so that how to select these values
You'll need to split the text, convert each value to an integer, and build up a parameterized SQL command using the
IN
operator:
string text = YourTextBox.Text;
string[] parts = text.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
string[] parameterNames = new string[parts.Length];
SqlParameter[] parameters = new SqlParameter[parts.Length];
for (int index = 0; index < parts.Length; index++)
{
int value;
if (!int.TryParse(parts[index], out value))
{
return;
}
string name = "@p" + index;
parametersNames[index] = name;
parameters[index] = new SqlParameter(name, SqlDbType.Int) { Value = value };
}
string sql = string.Format("SELECT * FROM table WHERE userID IN ({0})", string.Join(", ", parameterNames));
using (var connection = new SqlConnection("..."))
using (var command = new SqlCommand(sql, connection))
{
command.Parameters.AddRange(parameters);
...
}