如何在sql命令中传递checkboxlist选中的项目 [英] how to pass checkboxlist selected items in sql command

查看:66
本文介绍了如何在sql命令中传递checkboxlist选中的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用sql命令中checkboxlist中选择的multipal值



现在我使用

SqlCommand cmd = new SqlCommand(SELECT CustID ,[P1],[P2]从temp1向上枢轴((P1,P2)中ProductID的总和(数量))按照CustID,con)的pvt顺序;





但是我想在sql命令中使用P1,P2的动态值。



任何人都可以帮助我,



提前感谢。

How to use multipal values selected in checkboxlist in sql command

now i use
SqlCommand cmd = new SqlCommand("SELECT CustID,[P1],[P2] from temp1 up pivot(sum (quantity) for ProductID in (P1,P2) ) as pvt order by CustID",con);


but i want use Dynamic value of P1, P2 in sql command.

any one can help me,

thanks in advance.

推荐答案

你可以添加一个javascript函数来连接这样的列表框值



You ca add a javascript function to concate list box value like this

function listBoxToString(listBox,all) {
    if (typeof listBox === "string") {
        listBox = document.getElementById(listBox);
    }
    if (!(listBox || listBox.options)) {
        throw Error("No options");
    }
    var options=[],opt;
    for (var i=0, l=listBox.options.length; i < l; ++i) {
        opt = listBox.options[i];
        if (all || opt.selected ) {
            options.push(opt.value);
        }
    }
    return options.join(",");
}







那么你需要将它传递给sql参数

喜欢@ListBoxValue,它应该是字符串类型。

之后你需要创建一个函数来分割这个值,或者你可以在sp登录中使用IN运算符



喜欢从表中选择*

其中id IN(@ListBoxValue)




then You need to pass it to sql parameter
like @ListBoxValue , It should be string type.
after that you need to create a function to split this value or you can use IN Operator in sp login

like Select * from table
where id IN (@ListBoxValue)


这篇关于如何在sql命令中传递checkboxlist选中的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆