当前位置: 首页>>代码示例>>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;未经允许,请勿转载。