如何更新两个表中的记录一起单击一次更新按钮? [英] how to update two tables record together in one update button click?

查看:65
本文介绍了如何更新两个表中的记录一起单击一次更新按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家早安..

在我的项目的aspx页中,同时保存了插入到两个表的操作,其中一个是tblcurrencysale和tblAssets
tblcurrencysale(csID(pk,autoincrement),csPurchaseAmount,csSoldamt,csprofit,csDate)
tblAssets(aID(pk,autoincre),aCash,aDate)
并且在tblAssets中添加了来自csprofit的aCash和来自csDate的aDate..
这是保存过程..我创建了sp及其工作正常..
但是在更新时,仅在tblcurrencysale table.i中更新了sp ..

hi good morning everyone..

in my project in aspx page while saving am inserting to two tables one is tblcurrencysale and tblAssets
tblcurrencysale(csID(pk,autoincrement),csPurchaseAmount,csSoldamt,csprofit,csDate)
tblAssets(aID(pk,autoincre),aCash,aDate)
and in tblAssets am adding aCash from csprofit and aDate from csDate..
this is the saving procedure..and i created sp and its working fine..
but while updating ,updating only in tblcurrencysale table.i gave sp..

UpdateAllPL objPL=new UpdateAllPL(); 
objPL.PurchaseAmount=tbPurchase.Text; 
objPL.SoldAmount=tbSold.Text; 
objPL.Profit=tbProfit.Text; 
objPL.Date=tbDate.Text; 
UpdateAllBLL objBLL=new UpdateAllBLL(); 
objBLL.UpdateCurrencySale(objPL); 
objPL.aCash=tbProfit.Text; 
objPL.aDate=tbDate.Text; 
objBLL.UpdateAssets(objPL); 
lblMessage.Text="Updated SuccessFully..."; 


这是我从类文件中获取的sp.call.但是Assets表未更新..

所以你可以建议我做at吗?

确实对我有帮助..谢谢


here is my sp am callin from class file..but Assets table is not updating ..

so can u suggest me wat have to do?

really it will help for me..thanks

推荐答案

看人,我不太了解,但是如果您始终使用它们,我建议您将它们放在一个过程中或者,如果您在代码中单独使用每个代码,那么创建新过程并将它们以这种方式组合到一个过程中,就可以一次调用proc了.
look man i don''t understand good but if you always use them together i advise to put them in one procedure or if you use each alone in your code so create new procedure and combine them together in one procedure in this way you can call the proc one time it is nice regards


此查询是否正确且做你想做的事?

在WHERE子句中使用相同字段的情况下更新字段看起来不正确:
Is this query correct and doing what you want to?

Updating a field where using the same field in the WHERE clause looks incorrect:
set aCash=@Cash,aDate=@Date where aCash=@Cash



在where子句中根据新现金本身分配现金通常不会找到数据.
当前,如果任何行已具有与要更新的新传递的金额相同的金额,则查询将起作用或无效.

1.应该有一些唯一的ID,以找到要更新的唯一行记录
2.您直接将文本框的数据传递给DB,对其进行修剪. (因此,您还应注意数据类型,但从一开始就可以使用它!)

顺便说一句,我假设您已调试,并且没有运行时错误,只是逻辑上的.



Assigning a cash based on new cash itself in the where clause will not find the data most of the times.
Currently, if any row already has the same amount as the new amount passed to be updated, query would work or else not.

1. There should be some unique id to find the unique row record to update
2. You are directly passing the data of textbox to DB, trim it. (As such you should also take care of datatype but to start with, you can live with it!)

BTW, I assume you DEBUGGED and there was no runtime error, only logical.


两个表之间的关系是什么.在两个表之间建立关系并将其放在update的where子句中查询tblassets(我把它放在下划线).我可能不知道您的要求,但是我想您必须通过身份字段而不是购买金额来更新tblcurrencySale

Whats the relation between both the table.. make a relation between both table and put it in where clause in update query of tblassets(I maked it underline). either I dont know about your requirement but then also, I think you have to update your tblcurrencySale through a identity field not by purchase amount

create proc ups_UpdateCurrencySale 
@PurchaseAmount varchar(50), 
@SalesAmount varchar(50), 
@Profit varchar(50), 
@Date varchar(50) 
AS BEGIN 

Update tblCurrencySale set 
csPurchaseAmount=@PurchaseAmount,
csSalesAmount=@SalesAmount,
csProfit=@Profit,
csDate=@Date 
where csPurchaseAmount=@PurchaseAmount 


update tblAssets set aCash=@Profit,aDate=@Date where aCash=@Cash

end




谢谢




Thanks


这篇关于如何更新两个表中的记录一起单击一次更新按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆