Hello Michael,
From your description, you're developing a data access ASP.NET page which
will use Gridview to let users select some certain records to update, and
when performing the udpate, you will need to dynamically put all those
selected GridView Row(keys) into your SQL query statement (in the "in
(.....)" block), correct?
Based on my experience, for such scenario, you need to use dynamic SQL
execution. Fixed compiled store-procedure can not fully meet the
requirement here. For dynamic SQL Execution, you have the following options
here:
1. programmatically use string concatenate in your .net data access code to
build the SQL query statement(includes all the items choosed in gridview)
and then execute it through SQLCommand.
2. If you have other paramters in addition to the dynamic key list and you
still want to use a stored-procedure, you can create a stored-procedure
with an additional parameters, and provide a VarChar parameter which used
to hold the var-length key list(such as "('key1','key2',....)" ). And you
can concatenate these expression as a complete SQL statement in your
store-procedure and use "sp_executesql").
#Using sp_executesql
http://msdn2.microsoft.com/en-us/library/ms175170.aspx
BTW, for such dynamic SQL execution scenario, using stored procedure won't
help much on performance.
Hope this helps.
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.