当前位置: 首页>>代码示例>>C#>>正文


C# DataTable.BeginLoadData方法代码示例

本文整理汇总了C#中DataTable.BeginLoadData方法的典型用法代码示例。如果您正苦于以下问题:C# DataTable.BeginLoadData方法的具体用法?C# DataTable.BeginLoadData怎么用?C# DataTable.BeginLoadData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DataTable的用法示例。


在下文中一共展示了DataTable.BeginLoadData方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: readWholeWorkSheetNoIndex

        private void readWholeWorkSheetNoIndex(bool triggerCreateColumns, DataTable table) {
            while (Read()) {
                if (m_depth==m_maxRow){
                    break;                    
                }

                bool justAddedColumns=false;
                //DataTable columns
                if (triggerCreateColumns) {
                    if (_isFirstRowAsColumnNames||(_isFirstRowAsColumnNames&&m_maxRow==1)) {
                        for (int i=0; i<m_maxCol; i++) {
                            if (m_cellsValues[i]!=null&&m_cellsValues[i].ToString().Length>0)
                                table.AddColumnHandleDuplicate(m_cellsValues[i].ToString());
                            else
                                table.AddColumnHandleDuplicate(string.Concat(COLUMN, i));
                        }
                    } else {
                        for (int i=0; i<m_maxCol; i++) {
                            table.Columns.Add(i.ToString(CultureInfo.InvariantCulture), typeof(Object));
                        }
                    }

                    triggerCreateColumns=false;
                    justAddedColumns=true;
                    table.BeginLoadData();
                }

                if (!justAddedColumns&&m_depth>0&&!(_isFirstRowAsColumnNames&&m_maxRow==1)) {
                    table.Rows.Add(m_cellsValues);
                }
            }

            if (m_depth>0&&!(_isFirstRowAsColumnNames&&m_maxRow==1)) {
                table.Rows.Add(m_cellsValues);
            }
        }
开发者ID:fanfeilong,项目名称:exceltk,代码行数:36,代码来源:ExcelBinaryReader.cs

示例2: readWholeWorkSheetWithIndex

        //TODO: quite a bit of duplication with the noindex version
        private bool readWholeWorkSheetWithIndex(XlsBiffIndex idx, bool triggerCreateColumns, DataTable table) {
            m_dbCellAddrs=idx.DbCellAddresses;

            foreach (uint dbCellAddress in m_dbCellAddrs){
                if (m_depth==m_maxRow){
                    break;
                }

                // init reading data
                m_cellOffset=findFirstDataCellOffset((int)dbCellAddress);

                if (m_cellOffset==-2) {
                    return false;
                }

                if (m_cellOffset<0) {
                    return true;
                }

                //DataTable columns
                if (triggerCreateColumns) {
                    if (_isFirstRowAsColumnNames&&readWorkSheetRow()||(_isFirstRowAsColumnNames&&m_maxRow==1)) {
                        for (int i=0; i<m_maxCol; i++) {
                            if (m_cellsValues[i]!=null&&m_cellsValues[i].ToString().Length>0) {
                                table.AddColumnHandleDuplicate(m_cellsValues[i].ToString());
                            } else {
                                table.AddColumnHandleDuplicate(string.Concat(COLUMN, i));
                            }
                        }
                    } else {
                        for (int i=0; i<m_maxCol; i++) {
                            table.Columns.Add(i.ToString(CultureInfo.InvariantCulture), typeof(Object));
                        }
                    }

                    triggerCreateColumns=false;

                    table.BeginLoadData();
                }

                while (readWorkSheetRow()) {
                    table.Rows.Add(m_cellsValues);
                }

                //add the row
                if (m_depth>0&&!(_isFirstRowAsColumnNames&&m_maxRow==1)) {
                    table.Rows.Add(m_cellsValues);
                }
            }

            return true;
        }
开发者ID:fanfeilong,项目名称:exceltk,代码行数:53,代码来源:ExcelBinaryReader.cs

示例3: ReadDataSet

        private DataSet ReadDataSet() {
            var dataset = new DataSet();

            Dictionary<int, XlsxDimension> demensionDict = DetectDemension();

            for (int sheetIndex = 0; sheetIndex < m_workbook.Sheets.Count; sheetIndex++) {
                XlsxWorksheet sheet = m_workbook.Sheets[sheetIndex];
                var table = new DataTable(m_workbook.Sheets[sheetIndex].Name);

                ReadSheetGlobals(sheet);
                sheet.Dimension = demensionDict[sheetIndex];

                if (sheet.Dimension == null) {
                    continue;
                }

                m_depth = 0;
                m_emptyRowCount = 0;

                // Reada Columns
                if (!m_isFirstRowAsColumnNames) {
                    // No Sheet Columns
                    for (int i = 0; i < sheet.ColumnsCount; i++) {
                        table.Columns.Add(i.ToString(CultureInfo.InvariantCulture), typeof(Object));
                    }
                } else if (ReadSheetRow(sheet)) {
                    // Read Sheet Columns
                    Debug.Assert(m_cellsValues!=null);
                    for (int index = 0; index < m_cellsValues.Length; index++) {
                        if (m_cellsValues[index] != null && m_cellsValues[index].ToString().Length > 0) {
                            table.AddColumnHandleDuplicate(m_cellsValues[index].ToString());
                        } else {
                            table.AddColumnHandleDuplicate(string.Concat(COLUMN, index));
                        }
                    }
                } else {
                    continue;
                }

                // Read Sheet Rows
                table.BeginLoadData();
                while (ReadSheetRow(sheet)) {
                    table.Rows.Add(m_cellsValues);
                }
                if (table.Rows.Count > 0) {
                    dataset.Tables.Add(table);
                }

                // Read HyperLinks
                ReadHyperLinks(sheet, table);

                table.EndLoadData();
            }
            dataset.AcceptChanges();
            dataset.FixDataTypes();
            return dataset;
        }
开发者ID:fanfeilong,项目名称:exceltk,代码行数:57,代码来源:ExcelOpenXmlReader.cs

示例4: TestRowErrors

        public void TestRowErrors()
        {
            DataTable table = new DataTable();
            DataColumn col1 = table.Columns.Add("col1", typeof(int));
            DataColumn col2 = table.Columns.Add("col2", typeof(int));
            DataColumn col3 = table.Columns.Add("col3", typeof(int));

            col1.AllowDBNull = false;
            table.Constraints.Add("uc", new DataColumn[] { col2, col3 }, false);
            table.BeginLoadData();
            table.Rows.Add(new object[] { null, 1, 1 });
            table.Rows.Add(new object[] { 1, 1, 1 });
            try
            {
                table.EndLoadData();
                Assert.False(true);
            }
            catch (ConstraintException) { }
            Assert.True(table.HasErrors);
            DataRow[] rows = table.GetErrors();

            Assert.Equal(2, rows.Length);
            Assert.Equal("Column 'col1' does not allow DBNull.Value.", table.Rows[0].RowError);
            Assert.Equal("Column 'col2, col3' is constrained to be unique.  Value '1, 1' is already present."
                    , table.Rows[1].RowError);

            Assert.Equal(table.Rows[0].RowError, table.Rows[0].GetColumnError(0));
            Assert.Equal(table.Rows[1].RowError, table.Rows[0].GetColumnError(1));
            Assert.Equal(table.Rows[1].RowError, table.Rows[0].GetColumnError(2));

            Assert.Equal("", table.Rows[1].GetColumnError(0));
            Assert.Equal(table.Rows[1].RowError, table.Rows[1].GetColumnError(1));
            Assert.Equal(table.Rows[1].RowError, table.Rows[1].GetColumnError(2));
        }
开发者ID:dotnet,项目名称:corefx,代码行数:34,代码来源:DataRowTest2.cs

示例5: LoadDataException

        public void LoadDataException()
        {
            DataTable table = new DataTable();
            DataColumn col = new DataColumn();
            col.ColumnName = "Id";
            col.DataType = typeof(int);
            col.DefaultValue = 47;
            table.Columns.Add(col);
            UniqueConstraint uc = new UniqueConstraint("UK1", table.Columns[0]);
            table.Constraints.Add(uc);

            col = new DataColumn();
            col.ColumnName = "Name";
            col.DataType = typeof(string);
            col.DefaultValue = "Hello";
            table.Columns.Add(col);

            table.BeginLoadData();
            object[] row = { 147, "Abc" };
            DataRow newRow = table.LoadDataRow(row, true);

            object[] row1 = { 147, "Efg" };
            DataRow newRow1 = table.LoadDataRow(row1, true);

            object[] row2 = { 143, "Hij" };
            DataRow newRow2 = table.LoadDataRow(row2, true);

            try
            {
                table.EndLoadData();
                Assert.False(true);
            }
            catch (ConstraintException)
            {
            }
        }
开发者ID:dotnet,项目名称:corefx,代码行数:36,代码来源:DataTableTest.cs

示例6: FindByKey_DuringDataLoad

        public void FindByKey_DuringDataLoad()
        {
            DataTable table = new DataTable();
            table.Columns.Add("col1", typeof(int));
            table.PrimaryKey = new DataColumn[] { table.Columns[0] };

            table.Rows.Add(new object[] { 1 });
            table.Rows.Add(new object[] { 2 });
            table.AcceptChanges();

            table.BeginLoadData();
            table.LoadDataRow(new object[] { 1000 }, false);
            Assert.NotNull(table.Rows.Find(1));
            Assert.NotNull(table.Rows.Find(1000));
            table.EndLoadData();
            Assert.NotNull(table.Rows.Find(1000));
        }
开发者ID:dotnet,项目名称:corefx,代码行数:17,代码来源:DataRowCollectionTest2.cs


注:本文中的DataTable.BeginLoadData方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。