Tuesday, March 20, 2012

Passing an array to query in a table adapter

I'm looking for a way to pass an array of values as a parameter to a query in a table adapter. For example I want to run a query something like:

SELECT * FROM menu WHERE menu_role IN (@.roles)

And I could pass something like 'RegisteredUser, SuperUser, OtherUser' to the @.roles parameter.

For some reason I can't figure out a way to do this. Any help would be greatly appericated.

Thanks,

Ryan.

This is possible from only code behind. Dynamically create the string and assrign it to the select command of tableadapter.

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=319884&SiteID=1

check this link

|||Thanks, but I don't think that that helps my situation. I guess I will just have to create a query string on the fly even though I hate doing that.|||

Check if this helps:http://weblogs.sqlteam.com/dinakar/archive/2007/03/28/60150.aspx

|||

There's more than one way to skin a cat...

I was trying to figure out the same thing when I realized I could filter the data AFTER it was returned. I put it in a dataview and used the rowfilter property. Hope that helps!

|||My solutions was to create a stored procedure that dynamically setup the query on the fly before sending the results back. All in all it turned out to be a fairly elegant solution, although I do wish I could just pass an array in through a parameter.

No comments:

Post a Comment