public string DoSave() { string retval = "0"; SqlTransaction tran = null; try { var cn = new SqlConnection(_constr); cn.Open(); tran = cn.BeginTransaction(IsolationLevel.ReadUncommitted); var ds = new DsPurchase(); var dt = ds.PURCHASEREQUEST; var taPurMain = new PURCHASEREQUESTTableAdapter(); taPurMain.Connection.ConnectionString = _constr; taPurMain.Fill(dt); taPurMain.AssignConnection(cn,tran); taPurMain.Update(Purchaserequest); tran.Commit(); retval = "1"; } catch (Exception ex) { if (tran != null) tran.Rollback(); retval = ex.ToString(); } return retval; }
public string DoSavePurchaseRequestInRemote(DsPurchase.PURCHASEREQUESTDataTable dt) { var dm = new DataManager(); string retval="0"; SqlTransaction tran = null; var cn = new SqlConnection(_constr); try { cn.Open(); tran = cn.BeginTransaction(IsolationLevel.ReadUncommitted); var ds = new DsPurchase(); var dtdetail = ds.PURCHASEREQUEST; var taPurDetail = new PURCHASEREQUESTTableAdapter(); taPurDetail.AssignConnection(cn, tran); foreach (DsPurchase.PURCHASEREQUESTRow ditemdetarow in dt) { var newdetrow = dtdetail.NewRow(); foreach (DataColumn dc in dt.Columns) { if (!dc.ReadOnly) { newdetrow[dc.ColumnName] = ditemdetarow[dc.ColumnName]; } } dtdetail.Rows.Add(newdetrow); } taPurDetail.Update(dtdetail); tran.Commit(); retval = "1"; } catch (Exception ex) { if (cn != null) { if (tran != null) tran.Rollback(); } retval = ex.ToString(); } return retval; }