There are a few problems with your code.
First off, to fix your data type error, you'd have to convert strIDs
to integers before doing anything else. This should work
var ids = strIDs.Select(s => long.Parse(s));
Now, since you're using entity framework already, why not use Linq instead of creating a SQL query?
var results =
from r in myContext.MyTable
where ids.Contains(r.IDData)
select r;
Or in fluent syntax
var results = myContext.MyTable.Where(r => strIDs.Contains(r.IDData));
But if you really want to use SQL, the IN
operator does not support parameters like that. You'd have to write it like this:
strSQLQuery = "select * from MyTable where IDData IN(@ID1, @ID2, @ID3, ...)";
So to do this without too much effort, you can generate your query from ids
like this:
strSQLQuery = "select * from MyTable where IDData IN(" + String.Join(", ", ids.Select((s, i) => "@ID" + i)) + ")";
foreach(var parameter in ids.Select((s, i) => new SqlParameter("@ID" + i, s)))
{
lstParametros.Add(parameter);
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…