예제 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="mdt">主表</param>
        /// <param name="mtablename">主表表名</param>
        /// <param name="ddt">子表</param>
        /// <param name="dtablename">子表表名</param>
        /// <returns></returns>
        public static int Update(DataTable mdt, string mtablename, DataTable ddt, string dtablename, bool isupdate = false)
        {
            int    retvalue = 0;
            string msql     = @"SELECT  FNo, FTitle
             FROM  " + mtablename + " WHERE FNo = '';";
            string dsql     = "select * from " + dtablename + " WHERE FMNo = ''";

            if (isupdate)
            {
                //   msql = @"SELECT  FNo, FTitle
                //FROM  " + mtablename + " WHERE FNo = '"+mdt.Rows[0]["FNo"].ToString()+"'";
                //   dsql = "select * from " + dtablename + " WHERE FMNo = '"+ddt.Rows[0]["FMNo"].ToString()+"'";
                for (int i = 0; i < mdt.Rows.Count; i++)
                {
                    mdt.Rows[i][0] = mdt.Rows[i][0];
                    mdt.AcceptChanges();
                    mdt.Rows[i].SetModified();
                }

                DataRowState rowState = ddt.Rows[0].RowState;
                for (int i = 0; i < ddt.Rows.Count; i++)
                {
                    ddt.Rows[i][1] = ddt.Rows[i][1];
                    ddt.AcceptChanges();
                    ddt.Rows[i].SetModified();
                }
                rowState = ddt.Rows[0].RowState;
            }
            try
            {
                dBUtil.OpenConn();
                dBUtil.BeginTrans();
                retvalue  = dBUtil.Update(mdt, msql);
                retvalue += dBUtil.Update(ddt, dsql);
                dBUtil.CommitTrans();
            }
            catch (Exception ex)
            {
                dBUtil.RollbackTrans();
            }
            finally
            {
                dBUtil.CloseConn();
            }
            return(retvalue);
        }