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

NewRecord() private method

private NewRecord ( ) : int
return int
        internal int NewRecord() => NewRecord(-1);

Same methods

DataTable::NewRecord ( int sourceRecord ) : int

Usage Example

        private int ReadOldRowData(DataSet ds, ref DataTable table, ref int pos, XmlReader row)
        {
            // read table information
            table = ds.Tables[XmlConvert.DecodeName(row.LocalName), row.NamespaceURI];
            int    iRowDepth = row.Depth;
            string value     = null;

            if (table == null)
            {
                throw ExceptionBuilder.DiffgramMissingTable(XmlConvert.DecodeName(row.LocalName));
            }


            value = row.GetAttribute(Keywords.ROWORDER, Keywords.MSDNS);
            if ((value != null) && (value.Length > 0))
            {
                pos = (Int32)Convert.ChangeType(value, typeof(Int32));
            }

            int record = table.NewRecord();

            foreach (DataColumn col in table.Columns)
            {
                col[record] = DBNull.Value;
            }

            foreach (DataColumn col in table.Columns)
            {
                if ((col.ColumnMapping == MappingType.Element) ||
                    (col.ColumnMapping == MappingType.SimpleContent))
                {
                    continue;
                }

                if (col.ColumnMapping == MappingType.Hidden)
                {
                    value = row.GetAttribute("hidden" + col.EncodedColumnName, Keywords.MSDNS);
                }
                else
                {
                    value = row.GetAttribute(col.EncodedColumnName, col.Namespace);
                }

                if (value == null)
                {
                    continue;
                }

                col[record] = col.ConvertXmlToObject(value);
            }

            row.Read();
            if (row.Depth <= iRowDepth)
            {
                // the node is empty
                return(record);
            }

            if (table.XmlText != null)
            {
                DataColumn col = table.XmlText;
                col[record] = col.ConvertXmlToObject(row.ReadString());
            }
            else
            {
                while (row.Depth > iRowDepth)
                {
                    String     ln     = XmlConvert.DecodeName(row.LocalName);
                    String     ns     = row.NamespaceURI;
                    DataColumn column = table.Columns[ln, ns];

                    if (column == null)
                    {
                        while ((row.NodeType != XmlNodeType.EndElement) && (row.LocalName != ln) && (row.NamespaceURI != ns))
                        {
                            row.Read(); // consume the current node
                        }
                        row.Read();     // now points to the next column
                        continue;       // add a read here!
                    }


                    int iColumnDepth = row.Depth;
                    row.Read();
                    if (row.Depth > iColumnDepth)   //we are inside the column
                    {
                        if (row.NodeType == XmlNodeType.Text)
                        {
                            String text = row.ReadString();
                            column[record] = column.ConvertXmlToObject(text);

                            row.Read(); // now points to the next column
                        }
                    }
                    else
                    {
                        // <element></element> case
                        if (column.DataType == typeof(string))
                        {
                            column[record] = string.Empty;
                        }
                    }
                }
            }
            row.Read(); //now it should point to next row
            return(record);
        }
All Usage Examples Of System.Data.DataTable::NewRecord
DataTable