本文整理汇总了C#中DataTable.EndLoadData方法的典型用法代码示例。如果您正苦于以下问题:C# DataTable.EndLoadData方法的具体用法?C# DataTable.EndLoadData怎么用?C# DataTable.EndLoadData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataTable
的用法示例。
在下文中一共展示了DataTable.EndLoadData方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: readWholeWorkSheet
private DataTable readWholeWorkSheet(XlsWorksheet sheet) {
XlsBiffIndex idx;
if (!readWorkSheetGlobals(sheet, out idx, out m_currentRowRecord))
return null;
var table=new DataTable(sheet.Name);
const bool triggerCreateColumns = true;
if (idx!=null) {
readWholeWorkSheetWithIndex(idx, triggerCreateColumns, table);
} else {
readWholeWorkSheetNoIndex(triggerCreateColumns, table);
}
table.EndLoadData();
return table;
}
示例2: 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;
}
示例3: 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)
{
}
}
示例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));
}
示例5: 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));
}