c# - How do I loop a SQL parameter list and WHERE clause? Or get results more efficiently? -


what best approach? have c# .net web forms website gathers list of user profiles based on 1 or more tags. site connects sql database , uses stored procedures data retrieval.

my first (half-retarded) thought build list of parameters: tag1, tag2, tagn. pass list sp. in sp, build clause looping through parameters.

before can loop, how build parameters in sql?

it'd nice if pass sp array or list bust apart , build query. however, don't know how - if did, doubt efficiency desirable.

i can use commandtype.text , spit out huge query right there in code. doesn't sound efficient either. want keep sql/c# stuff separated possible. site mess , half..

do of have thoughts on this?

table valued parameters ideal solution here (assuming on sql server 2008). allow send sets of data sql server (in 2008 , above) , process data set in stored procs (which means can joins on set, use exists perhaps, etc).

if not on sql server 2008, have 2 options, first being construct xml document , use sql server's xml support (2005 , above) parse document entered (through string or xml parameter) data set can perform joins/filters on.

or, can send custom format use sql clr methods process (any kind of procedural code parsing more performant in sql clr methods; sql server better set-based operations).

finally, since dynamically generating query in code, don't have pass set parameter, can tack on parameters. however, goes without saying shouldn't call tostring , attach parameters; should create valid parameter name (not hard do) append set referenced in in clause , add parameter command proper value. makes assumption number of values referenced in clause doesn't exceed number of parameters allowed in command.


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -