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);
}
}
}
这里为了将选定的Chkbox列表数据插入到DB中,我需要多次调用该服务,这等于在复选框列表中选择的项目数....我可以通过调用一次来实现我的要求并插入选定的值
答案 0 :(得分: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,'Gopal,Reddy',2;