protected void bt_price2_Click(object sender, EventArgs e)
{
String Strsql1 = "UPDATE b SET iUnitCost=c.单价,iPrice=round(iQuantity*c.单价,2) from RdRecord a inner join RdRecords b on a.id=b.id INNER JOIN (select a.cBusCode as 业务号,b.cInvCode as 产品编码,b.iUnitCost as 单价 from RdRecord a left join RdRecords b on a.id=b.id where (a.dDate>='" + startTime.Text + "'and a.dDate<='" + endTime.Text + "')and a.cBusType ='转换出库' and (not b.iUnitCost is null and b.iunitcost<>0)) AS c ON c.业务号=a.cBusCode where (a.dDate>='" + startTime.Text + "'and a.dDate<='" + endTime.Text + "') and a.cBusType ='转换入库'and a.cRdCode='" + DropDownList2.Text + "' and a.cWhCode='" + whcode2.Text + "' and (b.iUnitcost is null or b.iunitcost=0)";
SqlCommand cmd = new SqlCommand(Strsql1, Conn);
Conn.Open();
if (Convert.ToInt32(cmd.ExecuteNonQuery()) > 0)
{
Response.Write("<script> alert('修改成功!!!')</script>");
}
else
{
Response.Write("<script> alert('无满足条件的记录!!!')</script>");
}
Label1.Visible = true;
Label1.Text = "共修改" + cmd.ExecuteNonQuery().ToString() + "条记录";
Conn.Close();
}
在查询分析器里测试SQL语句,没有问题,所影响行数不为0,但是在页面里测试,即使修改成功,返回值也是0
------解决方案--------------------------------------------------------
是数据修改成功但是不提示成功信息,还是数据压根就没修改~~
------解决方案--------------------------------------------------------
你确定数据库连接的不是其他数据库吗?
------解决方案--------------------------------------------------------
你的update语句被执行了2次了,可能第一次修改的时候有数据被修改,但第二次没有。
if (Convert.ToInt32(cmd.ExecuteNonQuery()) > 0)
{
Response.Write("<script> alert('修改成功!!!')</script>");
}
else
{
Response.Write("<script> alert('无满足条件的记录!!!')</script>");
}
Label1.Visible = true;
Label1.Text = "共修改" + cmd.ExecuteNonQuery().ToString() + "条记录";
改成
- C# code
int count=Convert.ToInt32(cmd.ExecuteNonQuery()); if (count > 0) { Response.Write("<script> alert('修改成功!!!')</script>"); } else { Response.Write("<script> alert('无满足条件的记录!!!')</script>"); } Label1.Visible = true; Label1.Text = "共修改" + count.ToString() + "条记录"; Conn.Close(); }
------解决方案--------------------------------------------------------