乐秀生成工具有时不能成功更新状态Bug



乐秀生成/状态更新代码如下:
string[] ids = new string[3];
int num = 60;//图片总数
int count = 0;//选中的图片总数
int currentcount = 0;//当前总数
int rand = (new Random()).Next(1, 60);

//计算选中的图片总数
for (int i = 0; i < num; i++)
    if (i % rand == 1)
        count++;

//生成
for (int i = 0; i < num; i++)
{
    if (i % rand == 1)
    {
        ids[currentcount % 3] = i + "";

        currentcount++;

        if (currentcount % 3 == 0 || (currentcount % 3 != 0 && currentcount == count))
        {
            //生成...

            string sql = "Update LX_ResTB SET [Status]=1 Where [Id] in(" + string.Join(",", ids) + ")";
            textBox1.Text += sql + "\r\n";
            //更新状态...
        }
    }
}

编辑反馈,有时状态更新不成功!测试后发现:当count的值小于3时,会构造出错误的sql语句(Update LX_ResTB SET [Status]=1 Where [Id] in(1624,1623,)),因而无法成功更新状态。

修改后的代码:
string[] ids = new string[3] { "0", "0", "0" };
int num = 60;//图片总数
int count = 0;//选中的图片总数
int currentcount = 0;//当前总数
int rand = (new Random()).Next(1, 60);

//计算选中的图片总数
for (int i = 0; i < num; i++)
    if (i % rand == 1)
        count++;

//生成
for (int i = 0; i < num; i++)
{
    if (i % rand == 1)
    {
        ids[currentcount % 3] = i + "";

        currentcount++;

        if (currentcount % 3 == 0 || (currentcount % 3 != 0 && currentcount == count))
        {
            //生成...

            string sql = "Update LX_ResTB SET [Status]=1 Where [Id] in(" + string.Join(",", ids) + ")";
            textBox1.Text += sql + "\r\n";
            //更新状态...
        }
    }
}


上一篇: 中国移动短信二次确认示例
下一篇: for循环小测试(C#)
文章来自: 本站原创
引用通告: 查看所有引用 | 我要引用此文章
Tags:
最新日志:
评论: 0 | 引用: 0 | 查看次数: 3345
发表评论
登录后再发表评论!