ok, I’m sure i’m not the only one that has wondered this =)
In a nutshell, is it possible using VisualStudio to convert:
string a1, string a2, string a3, string a4, string a5, string a6
into a string sorta like:
"'value1', 'value2', 'value3', 'value4', 'value5', value6'"
(don’t worry about the exact formatting, i can handle that myself)?
Background:
I often have functions that calls stored procedures that accept a lot of params, and sometimes (debugging) i need to build the “exec dbo.storedprocname param1, param2….” string and run it directly against the server. Currently i have to manually build the string and i’m hoping there’s an easy way to print it out in the immediate window in VisualStudio
EDIT (By popular demand):
I’m using Linq2SQL (yes, i knwo it’s obsolete) and have 100+ SP’s in it. When I need to debug a function, i put a break inside one of these functions to see what it’s about to pass to the database. So this would be RUNTIME. When it hits the breakpoint:
public static void MethodCreatedByLINQ2Sql(string param1, string param2, string param3, ...)
{
context.mystoredprocedure(param1, param2, param3...); //<---breakpoint
}
I want to somehow (without having to specify each param), print out a delimited string that i can cut & paste into SSMS2008 (trying to save time) to build a string like this
exec dbo.mystoredprocedure [['value1', 'value2', 'value3'......]] <--- pasted value from VisualStudio
No, i’m not trying to do SQLInjections or anything like that. I’m just trying to save time – some of these SP’s have 20+ params.
Is this what you’re after?
String paramStr = String.Format("'{0}', '{1}', '{2}', '{3}', '{4}'", a1, a2, a3,a4,a5);I should point out that sending strings like this to the DB can result in SQL Injection
Option 2:
To print the to the intermediate window you can use this trick:
{ String.Format(.....) }More about the params you can print in that message: http://msdn.microsoft.com/en-us/library/232dxah7.aspx