Jorell
asked on
List of IDs for Where In Clause
Hi there,
I have searched and found a few similar questions but the answers are confusing. I have a dataset that I need to pass a list of ID's. I can make it work with SQL Server with just 1,2,3 but even previewing data in the Dataset and using 1,2,3 as the param value fails
Select * from TableA
Where ID in (@IdList)
I am using VS2008 and VB.Net.
I can not use Stored Procs
Any help would be great!
Jase
I have searched and found a few similar questions but the answers are confusing. I have a dataset that I need to pass a list of ID's. I can make it work with SQL Server with just 1,2,3 but even previewing data in the Dataset and using 1,2,3 as the param value fails
Select * from TableA
Where ID in (@IdList)
I am using VS2008 and VB.Net.
I can not use Stored Procs
Any help would be great!
Jase
ASKER
How can you do that using a Dataset Table adapter??
i am not sure abt that part.. may be some other expert will help you
Okay without stored procedures, you can try using a split function as described here - http:Q_23786715.html - or search site for dbo.ParmsToList written by angel eyes. There is even a few articles that may be helpful.
Usage would be:
Select * from TableA Where ID in (select entry from dbo.split(@IdList, ',' ));
Usage would be:
Select * from TableA Where ID in (select entry from dbo.split(@IdList, ',' ));
ASKER
I know how to create a dynamic SQL statement. I need to pass the list as a param to a Dataset:
I.E. tableadapter.fill(dataset, IDLIST)
I.E. tableadapter.fill(dataset,
My solution wasn't using dynamic SQL, so you could basically setup a normal SqlCommand that takes a parameter. The code utilizes the split function to take the comma delimited string and create a table inline to use in the IN statement to avoid the need for dynamic SQL.
ASKER
Maybe I am missing something, how would I utilize the Typed Dataset and the Datagridview that is associated with that typed dataset using your method?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
exec ('Select * from TableA Where ID in ('+@IdList+ ')' )