首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

调试时可以一般保存,不进断点数据没有正常保存。请大牛们帮忙看看。添加Thread.Sleep(100)后可正常执行

2013-02-28 
调试时可以正常保存,不进断点数据没有正常保存。请大牛们帮忙看看。添加Thread.Sleep(100)后可正常执行本帖

调试时可以正常保存,不进断点数据没有正常保存。请大牛们帮忙看看。添加Thread.Sleep(100)后可正常执行
本帖最后由 wwwaone 于 2013-02-18 14:16:19 编辑 public string saveFundTableToOrderMoveInfo()
    {
        int countOk = 0, countNo = 0;
        string[] tempstr = str.Split('|');
        for (int i = 0; i < tempstr.Length - 1; i++)
        {
            //Thread.Sleep(100);
            string[] arrystr = tempstr[i].ToString().Split(',');
            int flag = stockBLL.orderMoveSave(ordersheetno, arrystr[0].ToString(), movesheetno, arrystr[1].ToString(), arrystr[2].ToString(), arrystr[3].ToString(), adduser, addDate, storageId, arrystr[4].ToString());

            if (flag == 0)
            {
                countOk = countOk + 1;
            }
            else
            {
                countNo = countNo + 1;
            }
        }

        try
        {
            DataTable dt = ExecuteCmd("*", "tb_yc_fund_table", "where sheetno='" + ordersheetno + "' and del_flag=0 and quehuo_flag=0 order by fund_id").Tables[0];
            if (dt.Rows.Count > 0)
            {
                ordermove.sheetno = movesheetno;
                ordermove.moveout_departId = Int32.Parse(departId);
                ordermove.moveout_storageId = Int32.Parse(storageId);
                ordermove.moveout_date = DateTime.Parse(addDate);
                ordermove.moveout_user = adduser;
                ordermove.movein_departId = Int32.Parse(indepartId);
                ordermove.movein_storageId = Int32.Parse(instorageId);
                for (int i = 0; i < dt.Rows.Count; i++)
                {


                    ordermove.product_id = Int32.Parse(dt.Rows[i]["product_id"].ToString());
                    ordermove.product_name = dt.Rows[i]["product_name"].ToString();
                    ordermove.product_classid = Int32.Parse(dt.Rows[i]["product_classid"].ToString());
                    ordermove.product_classname = dt.Rows[i]["product_classname"].ToString();
                    ordermove.product_standard = dt.Rows[i]["product_standard"].ToString();
                    ordermove.product_standardUnit = dt.Rows[i]["product_standardUnit"].ToString();
                    ordermove.product_unitRate = decimal.Parse(dt.Rows[i]["product_unitRate"].ToString());
                    ordermove.product_kunitRate = decimal.Parse(dt.Rows[i]["product_kunitRate"].ToString());

                    ordermove.move_price = decimal.Parse(dt.Rows[i]["should_getprice"].ToString());
                    ordermove.move_buynumb = decimal.Parse(dt.Rows[i]["order_num"].ToString());                            
 ordermove.product_buyUnit = dt.Rows[i]["product_buyUnit"].ToString();
                    ordermove.move_numb = decimal.Parse(dt.Rows[i]["should_getnum"].ToString());                           ordermove.product_storageUnit = dt.Rows[i]["product_storageUnit"].ToString();
                    ordermove.flag = dt.Rows[i]["order_demo"].ToString();

                    int flag = stockBLL.orderMoveAddNew(ordermove);
                    
                   ExecuteCmd("delete tb_yc_fund_table where sheetno='" + ordersheetno + "' and fund_id=" + dt.Rows[i]["fund_id"].ToString());

                    if (flag == 0)
                    {
                        countNo = countNo + 1;


                        
                    }
                    else
                    {
                        countOk = countOk + 1;
                    }
                }
            }
            //Thread.Sleep(100);
            int moveflag = ExecuteCmd("insert tb_yc_ordermove_send (sheetno,move_class,moveout_departId,moveout_storageId,movein_departId,movein_storageId,move_totalMoney,moveout_date,moveout_user) values ('" + movesheetno + "','','" + departId + "','" + storageId + "','" + indepartId + "','" + instorageId + "','" + tatalMoney + "','" + addDate + "','" + adduser + "')");

            if (moveflag > 0)
            {
                return "订单总共" + (tempstr.Length - 1) + "项商品\n\n成功保存入库:" + countOk + "项\n\n失败:" + countNo + "项";
            }
            else
            {
                return "订单总共" + (tempstr.Length - 1) + "项商品\n\n 入库保存失败!";
            }

        }
        catch (Exception ex)
        {
            return ex.Message;
        }
    }
[解决办法]
分次操作数据库有一个时间过程

ExecuteCmd里是不是每次都新打开数据库链接?如果是同一个数据库链接就不会有时间差的问题
[解决办法]
数据还没保存就已经执行到下一条了。。。
Sleep一下就有时间保存了。。
[解决办法]
连接用单例模式吧。。。

热点排行