Hi,
I'm in a scenario where I have to update and select the same value at the same time on a delete and update event on a gridview.
Like on row delete,
update table set column=(column-1) and then bind a textbox to the new value with a sql select.
I'm using an update and a separate query to select the new value. My question is that is this possible with a single query or a subquery ? Is transaction advised in this case ?
Here's what I'm doing currently
I'm in a scenario where I have to update and select the same value at the same time on a delete and update event on a gridview.
Like on row delete,
update table set column=(column-1) and then bind a textbox to the new value with a sql select.
I'm using an update and a separate query to select the new value. My question is that is this possible with a single query or a subquery ? Is transaction advised in this case ?
Here's what I'm doing currently
Code:
string updlayernp = "update administrator.uwnptrtydetail set gennoofinstallment=((gennoofinstallment)-1) where gennptreatysrno=? and gennplayersrno=? ";
string selnoofInstall = "select gennoofinstallment from administrator.uwnptrtydetail where gennptreatysrno=? and gennplayersrno=? ";
DB2Command updcomm=new DB2Command(updlayernp,con);
DB2Command mdpcount= new DB2Command(selnoofInstall, con);
updcomm.Parameters.Add(new DB2Parameter("gennptreatysrno",hfNpTrtNo.Value));
updcomm.Parameters.Add(new DB2Parameter("gennplayersrno", hfNpTrtLNo.Value));
mdpcount.Parameters.Add(new DB2Parameter("gennptreatysrno", hfNpTrtNo.Value));
mdpcount.Parameters.Add(new DB2Parameter("gennplayersrno", hfNpTrtLNo.Value));
try
{
con.Open();
updcomm.ExecuteNonQuery();
lblmdpStat.ForeColor = System.Drawing.Color.Green;
txtNoInstall.Text=(mdpcount.ExecuteScalar()).ToString();
lblmdpStat.Text = "Installment successfully deleted !";
}
catch (DB2Exception ex)
{
lblmdpStat.Text = "An error occured " + ex.ToString();
}
finally
{
if (con != null)
{
con.Close();
}
}