2015-01-08 56 views
0
protected void btnadd_Click(object sender, EventArgs e) 
{ 
    for (int i = 0; i < chkBusinessLocationDetails.Items.Count; i++) 
      { 
       if (chkBusinessLocationDetails.Items[i].Selected) 
       { 
        long RowId = myvalue 
        string json1 = "{'CommonCategory':" + chk.Items[i].Value + ",'CommonCategoryRowId':" + RowId + "}"; 
        status.Text = Classforhttprequest.HttpPost("http://localhost/MyService/MetaData.svc/CommonCategoryAttributesID", json1); 

       } 

      } 


} 

這裏爲了到DB來插入選定Chkbox列表數據,我需要調用服務的許多倍,等於在複選框列表中選擇項目的數量....我可以通過調用一次acheive我的要求和插入選定值避免多次的HttpRequest插入的CheckBoxList選擇數據

+0

不能只是在for循環中創建一個鍵值對列表,並在循環後移動HttpPost調用? – sudheeshix

+0

你會請執行代碼將如何.......... –

+0

它是[8月10日](http://nationaldaycalendar.com/days-2/national-lazy-day-august-10 /) 已經? – sudheeshix

回答

0

從此.....需要在DB

創建一個函數
create FUNCTION [dbo].[Splitter](@String varchar(MAX), @Delimiter char(1))  
returns @table TABLE (items varchar(MAX))  
as  
begin  
declare @idx int  
declare @slice varchar(8000)  

select @idx = 1  
    if len(@String)<1 or @String is null return  

while @idx!= 0  
begin  
    set @idx = charindex(@Delimiter,@String)  
    if @idx!=0  
     set @slice = left(@String,@idx - 1)  
    else  
     set @slice = @String  

    if(len(@slice)>0) 
     insert into @table(Items) values(@slice)  

    set @String = right(@String,len(@String) - @idx)  
    if len(@String) = 0 break  
end 
return end; 


然後在插入SP需要做的這樣。 ......

INSERT INTO CommonCategoryAttributes 
    (CommonCategoryRowId,CommonCategoryAttributeName,Priority) 
    SELECT @CommonCategoryRowId, @CommonCategoryAttributeName, @Priority 
    FROM dbo.[Split] (@CommonCategoryAttributeName, ',') 


它適用於EXEC CommonCategoryAttributesID 1, '戈帕爾,雷迪',2;