日期:2014-05-17 浏览次数:20494 次
private void toolStripButton3_Click(object sender, EventArgs e) { if (dataGridView1.SelectedRows.Count <= 0) { MessageBox.Show("你没有选择删除项!", "删除提示"); return; } DialogResult result = MessageBox.Show("是否删除选定项\r\n删除不可恢复!", "删除提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning); if (result == DialogResult.OK) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < dataGridView1.SelectedRows.Count; i++) { sb.Append(dataGridView1.SelectedRows[i].Cells["id"].Value); sb.Append(","); } //MessageBox.Show( sb.ToString().Substring(0, sb.Length - 1)); Material delm = new Material(); delm.DeleteList(sb.ToString().Substring(0, sb.Length - 1)); bindlist(); } } #region 修改时查询物料是否存在2 /// <summary> /// 修改时查询物料是否存在2 /// </summary> /// <param name="Material"></param> /// <returns></returns> public bool CEMID(Material CMID) { string sql = string.Format("select MID from [T_material] where MID ='{0}' and id <>{1}", CMID.MID, CMID.id); if (DataBase.GetRowCount(sql) > 0) return true; else return false; } #endregion
------解决方案--------------------
using(TransactionScope ts=new TransactionScope())
{
yourMethod1();
yourMethod2();
ts.Complete();
}
void yourMethod1()
{
...Db operations
if(xxx)
{
throw new Exception();
}
}
void yourMethod2()
{
...transaction supported wcf service
if(xxx)
{
throw new Exception();
}
}
------解决方案--------------------
百度 事务!!!!
------解决方案--------------------
业务逻辑有问题吧,插入成功肯定能查得到呀,插入不成功肯定查不到,只看插入成功与否就好了吧.
------解决方案--------------------
把事务加到最外面,就是执行方法的外面
都成功了再提交