Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Tuesday, February 19, 2013 4:13 PM
I have a need to take the results from a dataset row and pass it to a SQL query, so i need the entire System.Data.DataRow ItemArray put into a comma seperated string so i can pass it in as a parameter.
Is this possible and if so can anyone provide links to good source or possibly sample code to try?
thanks.
All replies (2)
Tuesday, February 19, 2013 4:16 PM ✅Answered
In general I don't think what you want will work unless you're dealing with all numbers. But to convert any list of items to a string you can use String.Join.
String.Join(",", items);
Alternatively you could use LINQ to build the list but I find the above syntax easier. Note that if you're dealing with strings then you'll need to write a more complex set of code because strings would need to be delimited by single quotes.
Michael Taylor - 2/19/2013
http://msmvps.com/blogs/p3net
Tuesday, February 19, 2013 7:48 PM ✅Answered
You can write UDF's that return or take tables-values as Parameters:
http://msdn.microsoft.com/en-us/library/bb510489.aspx
http://msdn.microsoft.com/en-us/library/ms191165.aspx
So making a function that just takes an array as paramter should be a piece of cake (after all a array is little more then a table with only one column).
And that would also mean you could give the entire array as parameter, instead of converting it to string. (beside I would always use Parameter syntax. Building a query as string beg's for SQL-Injections).
Let's talk about MVVM: http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/b1a8bf14-4acd-4d77-9df8-bdb95b02dbe2