本文整理汇总了C#中System.Data.DataColumn.GetAutoIncrementValue方法的典型用法代码示例。如果您正苦于以下问题:C# DataColumn.GetAutoIncrementValue方法的具体用法?C# DataColumn.GetAutoIncrementValue怎么用?C# DataColumn.GetAutoIncrementValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Data.DataColumn
的用法示例。
在下文中一共展示了DataColumn.GetAutoIncrementValue方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddRowToTable
//.........这里部分代码省略.........
XmlNodeList childList = tableNode.ChildNodes;
for (int i = 0; i < childList.Count; i++) {
XmlNode childNode = childList[i];
// we are looping through elements only
// Note : if an element is inferred as a table and has text, but also has child elements,
// the text is ignored.
if (childNode.NodeType != XmlNodeType.Element)
continue;
// Elements that have attributes are inferred as tables.
// Elements that have child elements are inferred as tables.
// Elements that repeat are inferred as a single table.
if (IsInferredAsTable(childNode)) {
// child node inferred as table
if (inferSchema) {
// We need to create new column for the relation between the current
// table and the new table we found (the child table).
string newRelationColumnName = table.TableName + "_Id";
if (!table.Columns.Contains(newRelationColumnName)) {
DataColumn newRelationColumn = new DataColumn(newRelationColumnName, typeof(int));
newRelationColumn.AllowDBNull = false;
newRelationColumn.AutoIncrement = true;
// we do not want to serialize this column so MappingType is Hidden.
newRelationColumn.ColumnMapping = MappingType.Hidden;
table.Columns.Add(newRelationColumn);
}
// Add a row to the new table we found.
AddRowToTable(childNode, table.Columns[newRelationColumnName], inferSchema, fillRows);
}
else
AddRowToTable(childNode, null, inferSchema, fillRows);
}
else {
// Elements that have no attributes or child elements, and do not repeat,
// are inferred as columns.
object val = null;
if (childNode.FirstChild != null)
val = childNode.FirstChild.Value;
else
val = "";
if (table.Columns.Contains(childNode.LocalName))
rowValue.Add(childNode.LocalName, val);
else if (inferSchema) {
table.Columns.Add(childNode.LocalName);
rowValue.Add(childNode.LocalName, val);
}
}
}
// Column can be attribute of the table element.
XmlAttributeCollection aCollection = tableNode.Attributes;
for (int i = 0; i < aCollection.Count; i++) {
XmlAttribute attr = aCollection[i];
//the atrribute can be the namespace.
if (attr.Prefix.Equals("xmlns"))
table.Namespace = attr.Value;
else { // the attribute is a column.
if (!table.Columns.Contains(attr.LocalName)) {
DataColumn col = table.Columns.Add(attr.LocalName);
col.ColumnMapping = MappingType.Attribute;
}
table.Columns[attr.LocalName].Namespace = table.Namespace;
rowValue.Add(attr.LocalName, attr.Value);
}
}
// If the current table is a child table we need to add a new column for the relation
// and add a new relation to the DataSet.
if (relationColumn != null) {
if (!table.Columns.Contains(relationColumn.ColumnName)) {
DataColumn dc = new DataColumn(relationColumn.ColumnName, typeof(int));
// we do not want to serialize this column so MappingType is Hidden.
dc.ColumnMapping = MappingType.Hidden;
table.Columns.Add(dc);
// Convention of relation name is: ParentTableName_ChildTableName
DataRelation dr = new DataRelation(relationColumn.Table.TableName + "_" + dc.Table.TableName, relationColumn, dc);
dr.Nested = true;
DSet.Relations.Add(dr);
UniqueConstraint.SetAsPrimaryKey (dr.ParentTable.Constraints, dr.ParentKeyConstraint);
}
rowValue.Add (relationColumn.ColumnName, relationColumn.GetAutoIncrementValue());
}
// Create new row and add all values to the row.
// then add it to the table.
DataRow row = table.NewRow ();
IDictionaryEnumerator enumerator = rowValue.GetEnumerator ();
while (enumerator.MoveNext ()) {
row [enumerator.Key.ToString ()] = StringToObject (table.Columns[enumerator.Key.ToString ()].DataType, enumerator.Value.ToString ());
}
if (fillRows)
table.Rows.Add (row);
}