c# - Bulk Update stored procedure with user input (WITHOUT A DATATABLE) -


can perform bulk update using stored procedure sends data temp table user input not in datatable.

if have foreach loop takes user input such values checkboxlist , text boxes want know how parameterize separate values in stored procedure or if can in code. cannot use table-valued parameters since i'm using version of sql not support it.

 conn.open();   foreach(listitem item in checkboxlist1.items)  {     if(item.selected)     {         //handling parameters in loop.         cmd.commandtype = commandtype.storedprocedure;         cmd.commandtext = "update_account_table";         cmd.parameters["@seqnum"].value = amount.text;         cmd.parameters["@seqdate"].value = datetime.parseexact(datepicker.text, "mmddyyyy", cultureinfo.invariantculture);         cmd.parameters["@account_id"].checkboxlist1.selectedvalue;          cmd.executenonquery();     }      conn.close();  } 

stored procedure

create table temptable (     seqnum int,     seqdate datetime,     account_id varchar(2) );    create procedure [accounttable_update]      set nocount on      begin         update accounttable         set seqnum = t.seqnum, seqdate = t.seqdate         accounttable @         inner join temptable t on at.accountid = t.accountid     end 

this uses dynamic table name in stored procedure, , sets value based on incoming parameter. use code below instead of temp table, or use parameters @seqnum, @seqdate, @acctid in place of @stats_value below:

use [eoddata] go  /****** object:  storedprocedure [dbo].[erase_stats]    script date: 8/23/2016 4:32:55 pm ******/ set ansi_nulls on go  set quoted_identifier on go  create procedure [dbo].[erase_stats]     @table varchar(25), @stats_value int begin     -- set nocount on added prevent result sets     -- interfering select statements.     set nocount on;     declare @productssql nvarchar(max); set @productssql = 'update ' + @table + ' set stats_completed = @stats_value' exec sp_executesql @productssql end  go 

Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -