
SqlTransaction 已完成;它再也无法使用。
try{apc.sqlOpen();trans=apc.conn.BeginTransaction();comm=apc.conn.CreateCommand();com...
try
{
apc.sqlOpen();
trans = apc.conn.BeginTransaction();
comm = apc.conn.CreateCommand();
comm.Transaction = trans;
comm.Connection = apc.conn;
comm.CommandText = "update tb_users set Balance = " + (dbSource - (Double.Parse(txtMoney.Text))) + " where CarDID = '" + atmPubClass.strCard + "'";
comm.ExecuteNonQuery();
comm.CommandText = "update tb_users set Balance = " + (dbObject + (Double.Parse(txtMoney.Text))) + " where CarDID = '" + txtMuBiao.Text + "'";
comm.ExecuteNonQuery();
comm.CommandText = "insert tb_transfer (SourceCardID , TargetCardID , Cash ,Balance ,Time) values ('" + atmPubClass.strCard + "','" + txtMuBiao.Text + "'," + txtMoney.Text + "," + (dbSource - (Double.Parse(txtMoney.Text))) + ",getDate())";
comm.ExecuteNonQuery();
trans.Commit();
if (MessageBox.Show(this, "转账操作已经成功执行,是否打印凭条", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
{
String stid = "select max(TradeID) as tid from tb_transfer where CardID = '" + atmPubClass.strCard + "'";
SqlCommand cmd = new SqlCommand(stid, apc.conn);
SqlDataReader cdr = cmd.ExecuteReader();
this.Hide();
frm_zhuanReport fzp = new frm_zhuanReport(cdr["tid"].ToString());
fzp.ShowDialog();
}
else
{
this.Hide();
frm_main fm = new frm_main();
fm.ShowDialog();
}
}
}
catch (Exception ex)
{
trans.Rollback();
MessageBox.Show(ex.Message);
}
finally
{
apc.sqlClose();
} 展开
{
apc.sqlOpen();
trans = apc.conn.BeginTransaction();
comm = apc.conn.CreateCommand();
comm.Transaction = trans;
comm.Connection = apc.conn;
comm.CommandText = "update tb_users set Balance = " + (dbSource - (Double.Parse(txtMoney.Text))) + " where CarDID = '" + atmPubClass.strCard + "'";
comm.ExecuteNonQuery();
comm.CommandText = "update tb_users set Balance = " + (dbObject + (Double.Parse(txtMoney.Text))) + " where CarDID = '" + txtMuBiao.Text + "'";
comm.ExecuteNonQuery();
comm.CommandText = "insert tb_transfer (SourceCardID , TargetCardID , Cash ,Balance ,Time) values ('" + atmPubClass.strCard + "','" + txtMuBiao.Text + "'," + txtMoney.Text + "," + (dbSource - (Double.Parse(txtMoney.Text))) + ",getDate())";
comm.ExecuteNonQuery();
trans.Commit();
if (MessageBox.Show(this, "转账操作已经成功执行,是否打印凭条", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
{
String stid = "select max(TradeID) as tid from tb_transfer where CardID = '" + atmPubClass.strCard + "'";
SqlCommand cmd = new SqlCommand(stid, apc.conn);
SqlDataReader cdr = cmd.ExecuteReader();
this.Hide();
frm_zhuanReport fzp = new frm_zhuanReport(cdr["tid"].ToString());
fzp.ShowDialog();
}
else
{
this.Hide();
frm_main fm = new frm_main();
fm.ShowDialog();
}
}
}
catch (Exception ex)
{
trans.Rollback();
MessageBox.Show(ex.Message);
}
finally
{
apc.sqlClose();
} 展开
3个回答
展开全部
你把catch中的 trans.Rollback();去掉就可以了。 因为前面已经trans.Commit();了,这个表示事物已经结束, 后面再调用当然会出现前面的问题了。
另外不用指明trans.Rollback(),如果有异常的话,事物会自动回滚的。
另外不用指明trans.Rollback(),如果有异常的话,事物会自动回滚的。
展开全部
你前面已经commint掉了 到后边又用这个事务
if (MessageBox.Show(this, "转账操作已经成功执行,是否打印凭条", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
{
String stid = "select max(TradeID) as tid from tb_transfer where CardID = '" + atmPubClass.strCard + "'";
SqlCommand cmd = new SqlCommand(stid, apc.conn);
SqlDataReader cdr = cmd.ExecuteReader();
this.Hide();
frm_zhuanReport fzp = new frm_zhuanReport(cdr["tid"].ToString());
fzp.ShowDialog();
}
肯定是不行的!
这种错误是说:你的事务在你第二次用前已经用完了!说明你这里面一个事务用了两次!第二次用的时候报的错!
if (MessageBox.Show(this, "转账操作已经成功执行,是否打印凭条", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
{
String stid = "select max(TradeID) as tid from tb_transfer where CardID = '" + atmPubClass.strCard + "'";
SqlCommand cmd = new SqlCommand(stid, apc.conn);
SqlDataReader cdr = cmd.ExecuteReader();
this.Hide();
frm_zhuanReport fzp = new frm_zhuanReport(cdr["tid"].ToString());
fzp.ShowDialog();
}
肯定是不行的!
这种错误是说:你的事务在你第二次用前已经用完了!说明你这里面一个事务用了两次!第二次用的时候报的错!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
帮顶+接分
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询