日期:2014-05-18  浏览次数:20902 次

c# 事务
[code=C#][/code]
  ckd ckd2 = new ckd();
  ckdsp ckdsp2 = new ckdsp();
  byte[] bytedatacdk2 = new byte[Marshal.SizeOf(typeof(ckd))];
  byte[] bytedatacdksp2 = new byte[Marshal.SizeOf(typeof(ckdsp))];
  FileStream fs2 = new FileStream(FileName, FileMode.Open, FileAccess.Read);
  string sql1,sql2,sql3;
   
  while (fs2.Read(bytedatacdk2, 0, bytedatacdk2.Length) == bytedatacdk2.Length)
  {

  ckd2 = (ckd)BytesToStuct(bytedatacdk2, typeof(ckd));

  try
  {
  sql1; //insert
  }
  catch
  {
  continue;
  }
  for (int j = 0; j < ckd2.wLength; j++)
  {

  if (fs2.Read(bytedatacdksp2, 0, bytedatacdksp2.Length) == bytedatacdksp2.Length)
  {
  ckdsp2 = (ckdsp)BytesToStuct(bytedatacdksp2, typeof(ckdsp));
  try
  {
  sql2; //insert
  }
  catch
  {
  continue;
  }
  try
  {
  sql3; //update
  }
  catch
  {
  continue;
  }
  }
  }
  }
执行完sql1,sql2,sql3才算完成一个事务,怎么给这段代码添加一个事务?

------解决方案--------------------
http://blog.csdn.net/chenshujun1127/article/details/2847710
将处理过程放到事务内