Exemple #1
0
        // https://blogs.msdn.microsoft.com/dotnet/2016/02/10/porting-to-net-core/
        // http://www.symbolsource.org/Public/Metadata/NuGet/Project/CSLA-Core/4.5.700/Release/.NETCore,Version%3Dv4.5/Csla/Csla/Csla.WinRT/Reflection/TypeExtensions.cs?ImageName=Csla
        // https://blogs.msdn.microsoft.com/dotnet/2016/02/10/porting-to-net-core/
        // http://stackoverflow.com/questions/35370384/how-to-get-declared-and-inherited-members-from-typeinfo
        // System.Type t = typeof(DataTable);
        // return t.GetTypeInfo().GetDeclaredField(fieldName);
        // GetTypeInfo().IsSubclassOf.
        // order to get access to the additional type information you have to invoke an extension method called GetTypeInfo()
        // that lives in System.Reflection.
        // typeof(DataTable).Assembly.Location


        public static void DataSetTest()
        {
            using (System.Data.DataSet ds = new System.Data.DataSet())
            {
                System.Console.WriteLine(ds.Tables.Count);

                System.Data.DataTable dt1 = ds.Tables["foo"];
                System.Data.DataTable dt2 = ds.Tables[0];


                // DataTable[]

                //ds.Tables.AddRange();
                //ds.Tables.Add();

                // ds.HasErrors

                // ds.WriteXml
                // ds.WriteXmlSchema
                // ds.Load

                foreach (System.Data.DataTable dt in ds.Tables)
                {
                    System.Console.WriteLine(dt);
                    // dt.Locale
                }
            }
            System.Data.Common.DataAdapter da = null;
        } // End Sub DataSetTest
Exemple #2
0
        public virtual int UpdateAll(School_SystemDataSet6 dataSet)
        {
            if ((dataSet == null))
            {
                throw new global::System.ArgumentNullException("dataSet");
            }
            if ((dataSet.HasChanges() == false))
            {
                return(0);
            }
            global::System.Data.IDbConnection workConnection = this.Connection;
            if ((workConnection == null))
            {
                throw new global::System.ApplicationException("TableAdapterManager contains no connection information. Set each TableAdapterMana" +
                                                              "ger TableAdapter property to a valid TableAdapter instance.");
            }
            bool workConnOpened = false;

            if (((workConnection.State & global::System.Data.ConnectionState.Broken)
                 == global::System.Data.ConnectionState.Broken))
            {
                workConnection.Close();
            }
            if ((workConnection.State == global::System.Data.ConnectionState.Closed))
            {
                workConnection.Open();
                workConnOpened = true;
            }
            global::System.Data.IDbTransaction workTransaction = workConnection.BeginTransaction();
            if ((workTransaction == null))
            {
                throw new global::System.ApplicationException("The transaction cannot begin. The current data connection does not support transa" +
                                                              "ctions or the current state is not allowing the transaction to begin.");
            }
            global::System.Collections.Generic.List <global::System.Data.DataRow>                     allChangedRows = new global::System.Collections.Generic.List <global::System.Data.DataRow>();
            global::System.Collections.Generic.List <global::System.Data.DataRow>                     allAddedRows   = new global::System.Collections.Generic.List <global::System.Data.DataRow>();
            global::System.Collections.Generic.List <global::System.Data.Common.DataAdapter>          adaptersWithAcceptChangesDuringUpdate = new global::System.Collections.Generic.List <global::System.Data.Common.DataAdapter>();
            global::System.Collections.Generic.Dictionary <object, global::System.Data.IDbConnection> revertConnections = new global::System.Collections.Generic.Dictionary <object, global::System.Data.IDbConnection>();
            int result = 0;

            global::System.Data.DataSet backupDataSet = null;
            if (this.BackupDataSetBeforeUpdate)
            {
                backupDataSet = new global::System.Data.DataSet();
                backupDataSet.Merge(dataSet);
            }
            try {
                // ---- Prepare for update -----------
                //
                //
                //---- Perform updates -----------
                //
                if ((this.UpdateOrder == UpdateOrderOption.UpdateInsertDelete))
                {
                    result = (result + this.UpdateUpdatedRows(dataSet, allChangedRows, allAddedRows));
                    result = (result + this.UpdateInsertedRows(dataSet, allAddedRows));
                }
                else
                {
                    result = (result + this.UpdateInsertedRows(dataSet, allAddedRows));
                    result = (result + this.UpdateUpdatedRows(dataSet, allChangedRows, allAddedRows));
                }
                result = (result + this.UpdateDeletedRows(dataSet, allChangedRows));
                //
                //---- Commit updates -----------
                //
                workTransaction.Commit();
                if ((0 < allAddedRows.Count))
                {
                    global::System.Data.DataRow[] rows = new System.Data.DataRow[allAddedRows.Count];
                    allAddedRows.CopyTo(rows);
                    for (int i = 0; (i < rows.Length); i = (i + 1))
                    {
                        global::System.Data.DataRow row = rows[i];
                        row.AcceptChanges();
                    }
                }
                if ((0 < allChangedRows.Count))
                {
                    global::System.Data.DataRow[] rows = new System.Data.DataRow[allChangedRows.Count];
                    allChangedRows.CopyTo(rows);
                    for (int i = 0; (i < rows.Length); i = (i + 1))
                    {
                        global::System.Data.DataRow row = rows[i];
                        row.AcceptChanges();
                    }
                }
            }
            catch (global::System.Exception ex) {
                workTransaction.Rollback();
                // ---- Restore the dataset -----------
                if (this.BackupDataSetBeforeUpdate)
                {
                    global::System.Diagnostics.Debug.Assert((backupDataSet != null));
                    dataSet.Clear();
                    dataSet.Merge(backupDataSet);
                }
                else
                {
                    if ((0 < allAddedRows.Count))
                    {
                        global::System.Data.DataRow[] rows = new System.Data.DataRow[allAddedRows.Count];
                        allAddedRows.CopyTo(rows);
                        for (int i = 0; (i < rows.Length); i = (i + 1))
                        {
                            global::System.Data.DataRow row = rows[i];
                            row.AcceptChanges();
                            row.SetAdded();
                        }
                    }
                }
                throw ex;
            }
            finally {
                if (workConnOpened)
                {
                    workConnection.Close();
                }
                if ((0 < adaptersWithAcceptChangesDuringUpdate.Count))
                {
                    global::System.Data.Common.DataAdapter[] adapters = new System.Data.Common.DataAdapter[adaptersWithAcceptChangesDuringUpdate.Count];
                    adaptersWithAcceptChangesDuringUpdate.CopyTo(adapters);
                    for (int i = 0; (i < adapters.Length); i = (i + 1))
                    {
                        global::System.Data.Common.DataAdapter adapter = adapters[i];
                        adapter.AcceptChangesDuringUpdate = true;
                    }
                }
            }
            return(result);
        }