System.Data.Tests.DataProvider.CreateChildDataTable C# (CSharp) Метод

CreateChildDataTable() публичный статический Метод

public static CreateChildDataTable ( ) : DataTable
Результат DataTable
        public static DataTable CreateChildDataTable()
        {
            DataTable dtChild = new DataTable("Child");
            dtChild.Columns.Add("ParentId", typeof(int));
            dtChild.Columns.Add("ChildId", typeof(int));
            dtChild.Columns.Add("String1", typeof(string));
            dtChild.Columns.Add("String2", typeof(string));
            dtChild.Columns.Add("ChildDateTime", typeof(DateTime));
            dtChild.Columns.Add("ChildDouble", typeof(double));

            dtChild.Rows.Add(new object[] { 1, 1, "1-String1", "1-String2", new DateTime(2000, 1, 1, 0, 0, 0, 0), 1.534 });
            dtChild.Rows.Add(new object[] { 1, 2, "2-String1", "2-String2", DateTime.MaxValue, -1.534 });
            dtChild.Rows.Add(new object[] { 1, 3, "3-String1", "3-String2", DateTime.MinValue, double.MaxValue / 10000 });
            dtChild.Rows.Add(new object[] { 2, 1, "1-String1", "1-String2", new DateTime(1973, 6, 20, 0, 0, 0, 0), double.MinValue * 10000 });
            dtChild.Rows.Add(new object[] { 2, 2, "2-String1", "2-String2", new DateTime(2008, 12, 1, 13, 59, 59, 59), 0.45 });
            dtChild.Rows.Add(new object[] { 2, 3, "3-String1", "3-String2", new DateTime(2003, 1, 1, 1, 1, 1, 1), 0.55 });
            dtChild.Rows.Add(new object[] { 5, 1, "1-String1", "1-String2", new DateTime(2002, 1, 1, 1, 1, 1, 1), 0 });
            dtChild.Rows.Add(new object[] { 5, 2, "2-String1", "2-String2", new DateTime(2001, 1, 1, 1, 1, 1, 1), 10 });
            dtChild.Rows.Add(new object[] { 5, 3, "3-String1", "3-String2", new DateTime(2000, 1, 1, 1, 1, 1, 1), 20 });
            dtChild.Rows.Add(new object[] { 6, 1, "1-String1", "1-String2", new DateTime(2000, 1, 1, 1, 1, 1, 0), 25 });
            dtChild.Rows.Add(new object[] { 6, 2, "2-String1", "2-String2", new DateTime(2000, 1, 1, 1, 1, 0, 0), 30 });
            dtChild.Rows.Add(new object[] { 6, 3, "3-String1", "3-String2", new DateTime(2000, 1, 1, 0, 0, 0, 0), 35 });
            dtChild.AcceptChanges();
            return dtChild;
        }

Usage Example

Пример #1
0
        public void AddNew()
        {
            //create the source datatable
            DataTable dt = DataProvider.CreateChildDataTable();

            //create the dataview for the table
            DataView dv = new DataView(dt);

            int CountView  = dv.Count;
            int CountTable = dt.Rows.Count;

            DataRowView drv = null;

            // AddNew - DataView Row Count
            drv = dv.AddNew();
            Assert.Equal(dv.Count, CountView + 1);

            // AddNew - Table Row Count
            Assert.Equal(dt.Rows.Count, CountTable);

            // AddNew - new row in DataTable
            drv.EndEdit();
            Assert.Equal(dt.Rows.Count, CountTable + 1);

            // AddNew - new row != null
            Assert.Equal(true, drv != null);

            // AddNew - check table
            Assert.Equal(dt, drv.Row.Table);
        }
All Usage Examples Of System.Data.Tests.DataProvider::CreateChildDataTable