检查checkedlistbox中的多个值

时间:2012-02-17 10:59:44

标签: c#

我有一个checkedlistbox,其中我有12个月..我想检查所选月份费用是否已经从数据库中支付。

此外,如果支付了1个月的费用且我选择的其他费用未支付,那么它应该验证并显示本月已付款而其他人应该进入数据网格以便接收。

我已经完成了1个月的选择,但是当我选择多个月时,我从数据库对此查询中没有获得任何价值

sql查询是

select Status from dbo.table where Month='Jan', 'Feb' ,'March'

如何在三行中获得一个列值?

1 个答案:

答案 0 :(得分:0)

问题不是很清楚。

如果您想从检查列表框中获取所选月份,然后获取所选月份的状态,您可以这样做: -

        string months = String.Empty;

        foreach (var item in checkedListBox1.CheckedItems)
        {
            months += "months = '"+item.ToString()+"' or ";
        }
        months = months.Substring(0, months.Length - 4);

现在通过以下方式创建您的查询字符串: -

string SelectQuery = "select Status from dbo.table where " + months;

如果你有月份列表,那么如果你想选择相应的复选框你可以这样做(假设你有“1月,3月,4月”格式的月份值);

string month = "January,March,December";
foreach (string item in month.Split(','))
        {

            checkedListBox1.SetItemChecked(checkedListBox1.Items.IndexOf(item),true);
        }
相关问题