string sqlBudget = "select b.* from BudgetApplicationAndPayout as b join WXFYLX as w on b.wid=w.id where w.ssnf='2013'";
DataTable budget = this.CommonBLL.getResult(sqlBudget);
if (budget.Rows.Count == 0)
{
insSQL = new System.Text.StringBuilder();
insSQL.Append("insert into BudgetApplicationAndPayout (wid) select id from WXFYLX where WXFYLX.ssnf='2013'");
insSQL.Append(@"update BudgetApplicationAndPayout set firstjdje=0.00,secondlyjdje=0.00,thirdjdje=0.00,fourjdje=0.00
,jdjeTotal=0.00,Janbk=0.00,Febbk=0.00,Marbk=0.00,Aprbk=0.00,Maybk=0.00,Junbk=0.00,Julbk=0.00,Augbk=0.00,Sepbk=0.00
,Octbk=0.00,Novbk=0.00,Decbk=0.00,yfjeTotal=0.00");
大家帮看一下怎么不行呢。
1、 if (budget== null||(budget!= null&&budget.Rows.Count<=0){}
2、你这样的代码可能会出现并发问题,所以可以合并的的查询和插入语法(SQL效率也比较高)
select count(*) from BudgetApplicationAndPayout as b join WXFYLX as w on b.wid=w.id where w.ssnf='2013'; IF @@ROWCOUNT = 0 Begin insert into BudgetApplicationAndPayout (wid) select id from WXFYLX where WXFYLX.ssnf='2013';
update BudgetApplicationAndPayout set firstjdje=0.00,secondlyjdje=0.00,thirdjdje=0.00,fourjdje=0.00,jdjeTotal=0.00,Janbk=0.00,Febbk=0.00,Marbk=0.00,Aprbk=0.00,Maybk=0.00,Junbk=0.00,Julbk=0.00,Augbk=0.00,Sepbk=0.00,Octbk=0.00,Novbk=0.00,Decbk=0.00,yfjeTotal=0.00; end
另外你上面的代码中。
insSQL.Append("insert into BudgetApplicationAndPayout (wid) select id from WXFYLX where WXFYLX.ssnf='2013'"); SQL语句语句的结尾没有分毫(;)
if(budget.Rows.Count <=0)
count属性返回的是 数字,怎么可能跟null比较呢,你现在的if语句永远都不执行,换成上面的判断
我那里是复制错了,换成if(budget.Rows.Count <=0)还是不行
@Ole_Yao: F10调试下,应该是有具体的错误,或者程序的运行情况不跟要的逻辑相同
楼上正解