System.Data.DataTable.CreateEmptyRow C# (CSharp) Method

CreateEmptyRow() private method

private CreateEmptyRow ( ) : DataRow
return DataRow
        internal DataRow CreateEmptyRow()
        {
            DataRow row = NewUninitializedRow();

            foreach (DataColumn c in Columns)
            {
                if (!XmlToDatasetMap.IsMappedColumn(c))
                {
                    if (!c.AutoIncrement)
                    {
                        if (c.AllowDBNull)
                        {
                            row[c] = DBNull.Value;
                        }
                        else if (c.DefaultValue != null)
                        {
                            row[c] = c.DefaultValue;
                        }
                    }
                    else
                    {
                        c.Init(row._tempRecord);
                    }
                }
            }
            return row;
        }

Usage Example

Ejemplo n.º 1
0
 internal void LoadData(XmlDocument xdoc)
 {
     if (xdoc.DocumentElement != null)
     {
         bool enforceConstraints;
         if (this.isTableLevel)
         {
             enforceConstraints = this.dataTable.EnforceConstraints;
             this.dataTable.EnforceConstraints = false;
         }
         else
         {
             enforceConstraints = this.dataSet.EnforceConstraints;
             this.dataSet.EnforceConstraints = false;
             this.dataSet.fInReadXml         = true;
         }
         if (this.isTableLevel)
         {
             this.nodeToSchemaMap = new XmlToDatasetMap(this.dataTable, xdoc.NameTable);
         }
         else
         {
             this.nodeToSchemaMap = new XmlToDatasetMap(this.dataSet, xdoc.NameTable);
         }
         DataRow row = null;
         if (this.isTableLevel || ((this.dataSet != null) && this.dataSet.fTopLevelTable))
         {
             XmlElement documentElement = xdoc.DocumentElement;
             DataTable  schemaForNode   = (DataTable)this.nodeToSchemaMap.GetSchemaForNode(documentElement, this.FIgnoreNamespace(documentElement));
             if (schemaForNode != null)
             {
                 row = schemaForNode.CreateEmptyRow();
                 this.nodeToRowMap[documentElement] = row;
                 this.LoadRowData(row, documentElement);
                 schemaForNode.Rows.Add(row);
             }
         }
         this.LoadRows(row, xdoc.DocumentElement);
         this.AttachRows(row, xdoc.DocumentElement);
         if (this.isTableLevel)
         {
             this.dataTable.EnforceConstraints = enforceConstraints;
         }
         else
         {
             this.dataSet.fInReadXml         = false;
             this.dataSet.EnforceConstraints = enforceConstraints;
         }
     }
 }
DataTable