當前位置: 首頁>>代碼示例>>C#>>正文


C# DataTable.EndLoadData方法代碼示例

本文整理匯總了C#中System.Data.DataTable.EndLoadData方法的典型用法代碼示例。如果您正苦於以下問題:C# DataTable.EndLoadData方法的具體用法?C# DataTable.EndLoadData怎麽用?C# DataTable.EndLoadData使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Data.DataTable的用法示例。


在下文中一共展示了DataTable.EndLoadData方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: DataReaderToDataSet

        public static DataSet DataReaderToDataSet(IDataReader reader)
        {
            var ds = new DataSet();
            DataTable table;
            do
            {
                int fieldCount = reader.FieldCount;
                table = new DataTable();
                for (int i = 0; i < fieldCount; i++)
                {
                    table.Columns.Add(reader.GetName(i), reader.GetFieldType(i));
                }
                table.BeginLoadData();
                var values = new Object[fieldCount];
                while (reader.Read())
                {
                    reader.GetValues(values);
                    table.LoadDataRow(values, true);
                }
                table.EndLoadData();

                ds.Tables.Add(table);

            } while (reader.NextResult());
            reader.Close();
            return ds;
        }
開發者ID:samnuriu13,項目名稱:APIXERP,代碼行數:27,代碼來源:Util.cs

示例2: GetDataSet

    public static  DataSet GetDataSet(String sqlString)
    {
        using (SqlCommand Cmd = new SqlCommand(sqlString))

            try
            {



                Cmd.CommandText = sqlString;
                Cmd.Connection = DbManager.Con;
                SqlDataAdapter dbDataAdapter = new SqlDataAdapter(Cmd);
                DataSet dataSet = new DataSet();
                DataTable dataTable = new DataTable();
                dataTable.BeginLoadData();
                dbDataAdapter.Fill(dataTable);
                dataTable.EndLoadData();
                dataSet.EnforceConstraints = false;
                dataSet.Tables.Add(dataTable);
                return dataSet;
            }

            catch (Exception ex)
            {
                throw;
            }
    }
開發者ID:vivek0tiwari,項目名稱:shaadisaagai,代碼行數:27,代碼來源:DbManager.cs

示例3: ConverDataReaderToDataTable

 public static DataTable ConverDataReaderToDataTable(IDataReader reader)
 {
     if (reader == null)
     {
         return null;
     }
     DataTable table = new DataTable
     {
         Locale = CultureInfo.InvariantCulture
     };
     int fieldCount = reader.FieldCount;
     for (int i = 0; i < fieldCount; i++)
     {
         table.Columns.Add(reader.GetName(i), reader.GetFieldType(i));
     }
     table.BeginLoadData();
     object[] values = new object[fieldCount];
     while (reader.Read())
     {
         reader.GetValues(values);
         table.LoadDataRow(values, true);
     }
     table.EndLoadData();
     return table;
 }
開發者ID:bookxiao,項目名稱:orisoft,代碼行數:25,代碼來源:DbHelperSQL.cs

示例4: ConvertDataReaderToDataTable

        public static DataTable ConvertDataReaderToDataTable(DbDataReader reader)
        {
            try
            {
                DataTable table = new DataTable();
                int fieldCount = reader.FieldCount;
                for (int fieldIndex = 0; fieldIndex < fieldCount; ++fieldIndex)
                {
                    table.Columns.Add(reader.GetName(fieldIndex), reader.GetFieldType(fieldIndex));
                }

                table.BeginLoadData();

                object[] rowValues = new object[fieldCount];
                while (reader.Read())
                {
                    reader.GetValues(rowValues);
                    table.LoadDataRow(rowValues, true);
                }
                reader.Close();
                table.EndLoadData();

                return table;

            }
            catch (Exception ex)
            {
                throw new Exception("DataReader轉換為DataTable時出錯!", ex);
            }
        }
開發者ID:piaolingzxh,項目名稱:Justin,代碼行數:30,代碼來源:DBHelper.cs

示例5: ProcessResult

		protected override DataTable ProcessResult(DataTable schema)
		{
			schema.BeginLoadData();

			foreach (DataRow row in schema.Rows)
			{
				// ToBoolean
				foreach (DataColumn col in schema.Columns)
					if (col.Caption.StartsWith("IS_"))
						row[col.Caption] =
							row[col.Caption] != DBNull.Value &&
								Convert.ToInt32(row[col.Caption], CultureInfo.InvariantCulture) != 0;

				if (Convert.ToInt32(row["HELPER_CID"], CultureInfo.InvariantCulture) != 0)
					row["SOURCE"] =
						HelperGetObjectDefinition(Convert.ToInt32(row["HELPER_CID"], CultureInfo.InvariantCulture));
			}

			schema.EndLoadData();
			schema.AcceptChanges();

			schema.Columns.Remove("HELPER_CID");

			return schema;
		}
開發者ID:rsdn,項目名稱:janus,代碼行數:25,代碼來源:SqlCheckConstraints.cs

示例6: getDifferentRecords

        public static DataTable getDifferentRecords(DataTable FirstDataTable, DataTable SecondDataTable)
        {
            FirstDataTable = FirstDataTable.Copy();
            FirstDataTable.TableName += " First";
            SecondDataTable = SecondDataTable.Copy();
            SecondDataTable.TableName += " Second";
            //Create Empty Table
            DataTable ResultDataTable = new DataTable("ResultDataTable");

            //use a Dataset to make use of a DataRelation object
            using (DataSet ds = new DataSet())
            {

                //Add tables
                ds.Tables.AddRange(new DataTable[] { FirstDataTable, SecondDataTable });

                //Get Columns for DataRelation
                DataColumn[] firstColumns = FirstDataTable.Columns.Cast<DataColumn>().ToArray();

                DataColumn[] secondColumns = SecondDataTable.Columns.Cast<DataColumn>().ToArray();

                //Create DataRelation
                DataRelation r1 = new DataRelation(string.Empty, firstColumns, secondColumns, false);
                ds.Relations.Add(r1);

                //DataRelation r2 = new DataRelation(string.Empty, secondColumns, firstColumns, false);
                //ds.Relations.Add(r2);

                //Create columns for return table
                List<DataColumn> PK = new List<DataColumn>();
                for (int i = 0; i < FirstDataTable.Columns.Count; i++)
                {
                    DataColumn newdc = ResultDataTable.Columns.Add(FirstDataTable.Columns[i].ColumnName, FirstDataTable.Columns[i].DataType);
                    if (FirstDataTable.PrimaryKey.Contains(FirstDataTable.Columns[i]))
                        PK.Add(newdc);
                }
                ResultDataTable.PrimaryKey = PK.ToArray();
                //If FirstDataTable Row not in SecondDataTable, Add to ResultDataTable.
                ResultDataTable.BeginLoadData();
                foreach (DataRow parentrow in FirstDataTable.Rows)
                {
                    DataRow[] childrows = parentrow.GetChildRows(r1);
                    if (childrows == null || childrows.Length == 0)
                        ResultDataTable.LoadDataRow(parentrow.ItemArray, true);
                }

                ////If SecondDataTable Row not in FirstDataTable, Add to ResultDataTable.
                //foreach (DataRow parentrow in SecondDataTable.Rows)
                //{
                //    DataRow[] childrows = parentrow.GetChildRows(r2);
                //    if (childrows == null || childrows.Length == 0)
                //        ResultDataTable.LoadDataRow(parentrow.ItemArray, true);
                //}
                ResultDataTable.EndLoadData();
            }
            return ResultDataTable;
        }
開發者ID:amoraller,項目名稱:AptekaAutoOrder,代碼行數:57,代碼來源:TableHelper.cs

示例7: ExecuteReader

 /// <summary>
 /// Create a command and call ExecuteReader. Load the data into a DataTable
 /// </summary>
 /// <param name="commandText">The command text</param>
 /// <param name="parameters">Parameters referring to @p1, @p2, ...</param>
 /// <returns></returns>
 public DataTable ExecuteReader(string commandText, params object[] parameters)
 {
     using (var command = this.CreateCommand(commandText, parameters))
     using (var reader = command.ExecuteReader())
     {
         var result = new DataTable();
         result.BeginLoadData();
         result.Load(reader);
         result.EndLoadData();
         reader.Close();
         return result;
     }
 }
開發者ID:kristiandupont,項目名稱:CherryTomato-classic,代碼行數:19,代碼來源:DatabaseConnection.cs

示例8: ProcessResult

        protected override DataTable ProcessResult(DataTable schema)
        {
            schema.BeginLoadData();

            foreach (DataRow row in schema.Rows)
                foreach (DataColumn col in schema.Columns)
                    if (col.Caption.StartsWith("IS_"))
                        row[col.Caption] =
                            row[col.Caption] != DBNull.Value &&
                                Convert.ToInt32(row[col.Caption], CultureInfo.InvariantCulture) != 0;

            schema.EndLoadData();
            schema.AcceptChanges();

            return schema;
        }
開發者ID:vai,項目名稱:nor,代碼行數:16,代碼來源:SqlPrimaryKeys.cs

示例9: Distinct

        public static DataTable Distinct(DataTable Table, DataColumn[] Columns)
        {
            //Empty table
            DataTable table = new DataTable("Distinct");

            //Sort variable
            string sort = string.Empty;

            //Add Columns & Build Sort expression
            for(int i = 0; i < Columns.Length; i++)
            {
                table.Columns.Add(Columns[i].ColumnName,Columns[i].DataType);
                sort += Columns[i].ColumnName + ",";
            }

            //Select all rows and sort
            DataRow[] sortedrows = Table.Select(string.Empty,sort.Substring(0,sort.Length-1));

            object[] currentrow = null;
            object[] previousrow = null;

            table.BeginLoadData();
            foreach(DataRow row in sortedrows)
            {
                //Current row
                currentrow = new object[Columns.Length];
                for(int i = 0; i < Columns.Length; i++)
                {
                    currentrow[i] = row[Columns[i].ColumnName];
                }

                //Match Current row to previous row
                if(!RowEqual(previousrow, currentrow))
                    table.LoadDataRow(currentrow,true);

                //Previous row
                previousrow = new object[Columns.Length];
                for(int i = 0; i < Columns.Length; i++)
                {
                    previousrow[i] = row[Columns[i].ColumnName];
                }
            }

            table.EndLoadData();
            return table;
        }
開發者ID:jbennie,項目名稱:tbldefexport,代碼行數:46,代碼來源:DataTableHelper.cs

示例10: _Intersect

        //Intersection
        //Union
        //Difference
        private DataTable _Intersect(
            DataTable parentTable, string pColName,
            DataTable childTable, string cColName)
        {
            DataTable parent = parentTable.Copy();
            DataTable child = childTable.Copy();
            //Creating Empty Table
            DataTable table = new DataTable("Intersect");

            //Creating Dataset to use DataRelation
            using (DataSet ds = new DataSet("IntersectedData"))
            {

                //Adding Tables to Dataset
                ds.Tables.AddRange(new DataTable[] { parent, child});

                //Creating columns for DataRelation
                DataColumn colParent = parent.Columns[pColName];
                DataColumn colChild = child.Columns[cColName];

                //Creating DataRelation
                DataRelation relIntersect = new DataRelation("RelIntersect", colParent, colChild);

                //Adding DataRelation to DataSet.
                ds.Relations.Add(relIntersect); //TODO: solve problem here

                //Cloning the Structure of Parent table to Return table.
                table = parent.Clone();

                //if Parent row is in Child table, Add it to Return table.
                table.BeginLoadData();
                foreach (DataRow parentRow in parent.Rows)
                {
                    DataRow[] childRows = parentRow.GetChildRows(relIntersect);

                    if (childRows.Length > 0)
                    {
                        table.LoadDataRow(parentRow.ItemArray, true);
                    }
                }//foreach parent row
                table.EndLoadData();
            }//using Dataset

            return table;            
        }//_Intersect
開發者ID:wshanshan,項目名稱:DDD,代碼行數:48,代碼來源:Controller_DB.cs

示例11: BuildSampleTable

        private DataTable BuildSampleTable()
        {
            var table = new DataTable();

            table.BeginInit();
            table.Columns.Add("COL-1", typeof(int));
            table.Columns.Add("COL-2");
            table.EndInit();

            table.BeginLoadData();
            for (var i = 0; i < 5; i++)
            {
                table.LoadDataRow(new object[] {i, (i + 1).ToString()}, true);
            }
            table.EndLoadData();

            return table;
        }
開發者ID:devlights,項目名稱:Sazare,代碼行數:18,代碼來源:DataTableExtensionsSample01.cs

示例12: Fetch

        public DataTable Fetch()
        {
            DataTable table = new DataTable();

            using (_connection = new SqlConnection(_connectionString))
            {
                _command = new SqlCommand(_sql, _connection);
                _connection.Open();

                table.BeginLoadData();
                SqlDataReader reader = _command.ExecuteReader();
                table.Load(reader);
                table.EndLoadData();

                reader.Close();
            }

            return table;
        }
開發者ID:charlest704,項目名稱:Lad-Solution,代碼行數:19,代碼來源:SimpleData.cs

示例13: ConvertDataReaderToDataSet

        /// <summary>
        /// Converts the data reader to data set.
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <returns>DataSet.</returns>
        public static DataSet ConvertDataReaderToDataSet(IDataReader reader)
        {
            DataSet ds = new DataSet();
            DataTable dataTable = new DataTable();

            DataTable schemaTable = reader.GetSchemaTable();
            DataRow row;

            string columnName;
            DataColumn column;
            int count = schemaTable.Rows.Count;

            for (int i = 0; i < count; i++)
            {
                row = schemaTable.Rows[i];
                columnName = (string)row["ColumnName"];

                column = new DataColumn(columnName, (Type)row["DataType"]);
                dataTable.Columns.Add(column);
            }

            ds.Tables.Add(dataTable);

            object[] values = new object[count];

            try
            {
                dataTable.BeginLoadData();
                while (reader.Read())
                {
                    reader.GetValues(values);
                    dataTable.LoadDataRow(values, true);
                }
            }
            finally
            {
                dataTable.EndLoadData();
                reader.Close();
            }

            return ds;
        }
開發者ID:jsheely,項目名稱:DotNetNuke-Data-Expose,代碼行數:47,代碼來源:Utils.cs

示例14: Fill

    public int Fill(DataTable table)
    {
      var reader = this.SelectCommand.ExecuteReader();
      if (table.Columns.Count < 1)
      {
        for (var i = 0; i < reader.FieldCount; i++)
        {
          table.Columns.Add(reader.GetName(i), reader.GetFieldType(i));
        }
      }

      int count = 0;
      DataRow row;
      object[] values = new object[reader.FieldCount];
      table.BeginLoadData();
      try
      {
        while (reader.Read())
        {
          row = table.NewRow();
          try
          {
            row.BeginEdit();
            reader.GetValues(values);
            row.ItemArray = values;
            table.Rows.Add(row);
          }
          finally
          {
            row.EndEdit();
            row.AcceptChanges();
          }
        }
      }
      finally
      {
        table.EndLoadData();
      }
      return count;
    }
開發者ID:rneuber1,項目名稱:InnovatorAdmin,代碼行數:40,代碼來源:DbAdapter.cs

示例15: Create

        /// <summary>
        /// Loads a DataTable from a sequence of objects.
        /// </summary>
        /// <param name="source">The sequence of objects to load into the DataTable.</param>
        /// <param name="table">The input table. The schema of the table must match that 
        /// the type T.  If the table is null, a new table is created with a schema 
        /// created from the public properties and fields of the type T.</param>
        /// <param name="options">Specifies how values from the source sequence will be applied to 
        /// existing rows in the table.</param>
        /// <returns>A DataTable created from the source sequence.</returns>
        public DataTable Create(IQueryable source)
        {
            var entityType = source.ElementType;
            var entityTypeProperties = entityType.GetProperties();

            var table = new DataTable(entityType.Namespace + "." + entityType.Name);
            var cols = entityTypeProperties.Select(p => new DataColumn(p.Name, Nullable.GetUnderlyingType(p.PropertyType) ?? p.PropertyType));
            table.Columns.AddRange(cols.ToArray());

            table.BeginLoadData();
            var entityEnumerator = source.GetEnumerator();

            while (entityEnumerator.MoveNext())
            {
                var values = entityTypeProperties.Select(p => p.GetValue(entityEnumerator.Current, null) ?? DBNull.Value);
                table.LoadDataRow(values.ToArray(), true);
            }

            table.EndLoadData();

            return table;
        }
開發者ID:vagwada,項目名稱:SqlCopy,代碼行數:32,代碼來源:EntityTableFactory.cs


注:本文中的System.Data.DataTable.EndLoadData方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。