当前位置: 首页>>代码示例>>C#>>正文


C# DataTable.ReadXmlSchema方法代码示例

本文整理汇总了C#中DataTable.ReadXmlSchema方法的典型用法代码示例。如果您正苦于以下问题:C# DataTable.ReadXmlSchema方法的具体用法?C# DataTable.ReadXmlSchema怎么用?C# DataTable.ReadXmlSchema使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DataTable的用法示例。


在下文中一共展示了DataTable.ReadXmlSchema方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: XmlSchemaTest5

        public void XmlSchemaTest5()
        {
            MakeParentTable();
            MakeChildTable();
            MakeSecondChildTable();
            MakeDataRelation();

            //Write
            using (FileStream stream = new FileStream(_tempFile, FileMode.Create))
            {
                _childTable.WriteXmlSchema(stream);
            }

            //Read
            DataTable table = new DataTable(_childTable.TableName);
            using (FileStream stream = new FileStream(_tempFile, FileMode.Open))
            {
                table.ReadXmlSchema(stream);
            }

            //Check Properties of the table
            Assert.Equal(string.Empty, table.Namespace);
            Assert.Null(table.DataSet);
            Assert.Equal(3, table.Columns.Count);
            Assert.Equal(0, table.Rows.Count);
            Assert.Equal(false, table.CaseSensitive);
            Assert.Equal("ChildTable", table.TableName);
            Assert.Equal(string.Empty, table.Prefix);
            Assert.Equal(1, table.Constraints.Count);
            Assert.Equal("Constraint1", table.Constraints[0].ToString());
            Assert.Equal(typeof(UniqueConstraint), table.Constraints[0].GetType());
            Assert.Equal(0, table.ParentRelations.Count);
            Assert.Equal(0, table.ChildRelations.Count);
            Assert.Equal(0, table.PrimaryKey.Length);

            //First Column
            DataColumn col = table.Columns[0];
            Assert.Equal(true, col.AllowDBNull);
            Assert.Equal(true, col.AutoIncrement);
            Assert.Equal(0, col.AutoIncrementSeed);
            Assert.Equal(1, col.AutoIncrementStep);
            Assert.Equal("Element", col.ColumnMapping.ToString());
            Assert.Equal("ChildID", col.ColumnName);
            Assert.Equal(typeof(int), col.DataType);
            Assert.Equal(string.Empty, col.DefaultValue.ToString());
            Assert.Equal(false, col.DesignMode);
            Assert.Equal("System.Data.PropertyCollection", col.ExtendedProperties.ToString());
            Assert.Equal(-1, col.MaxLength);
            Assert.Equal(0, col.Ordinal);
            Assert.Equal(string.Empty, col.Prefix);
            Assert.Equal("ChildTable", col.Table.ToString());
            Assert.Equal(true, col.Unique);

            //Second Column
            col = table.Columns[1];
            Assert.Equal(true, col.AllowDBNull);
            Assert.Equal(false, col.AutoIncrement);
            Assert.Equal(0, col.AutoIncrementSeed);
            Assert.Equal(1, col.AutoIncrementStep);
            Assert.Equal("Element", col.ColumnMapping.ToString());
            Assert.Equal("ChildItem", col.Caption);
            Assert.Equal("ChildItem", col.ColumnName);
            Assert.Equal(typeof(string), col.DataType);
            Assert.Equal(string.Empty, col.DefaultValue.ToString());
            Assert.Equal(false, col.DesignMode);
            Assert.Equal("System.Data.PropertyCollection", col.ExtendedProperties.ToString());
            Assert.Equal(-1, col.MaxLength);
            Assert.Equal(1, col.Ordinal);
            Assert.Equal(string.Empty, col.Prefix);
            Assert.Equal("ChildTable", col.Table.ToString());
            Assert.Equal(false, col.Unique);

            //Third Column
            col = table.Columns[2];
            Assert.Equal(true, col.AllowDBNull);
            Assert.Equal(false, col.AutoIncrement);
            Assert.Equal(0, col.AutoIncrementSeed);
            Assert.Equal(1, col.AutoIncrementStep);
            Assert.Equal("Element", col.ColumnMapping.ToString());
            Assert.Equal("ParentID", col.Caption);
            Assert.Equal("ParentID", col.ColumnName);
            Assert.Equal(typeof(int), col.DataType);
            Assert.Equal(string.Empty, col.DefaultValue.ToString());
            Assert.Equal(false, col.DesignMode);
            Assert.Equal("System.Data.PropertyCollection", col.ExtendedProperties.ToString());
            Assert.Equal(-1, col.MaxLength);
            Assert.Equal(2, col.Ordinal);
            Assert.Equal(string.Empty, col.Prefix);
            Assert.Equal("ChildTable", col.Table.ToString());
            Assert.Equal(false, col.Unique);
        }
开发者ID:dotnet,项目名称:corefx,代码行数:91,代码来源:DataTableTest3.cs

示例2: XmlSchemaTest6

        public void XmlSchemaTest6()
        {
            MakeParentTable();

            using (FileStream stream = new FileStream(_tempFile, FileMode.Create))
            {
                _parentTable.WriteXmlSchema(stream);
            }

            DataTable table = new DataTable();
            DataSet ds = new DataSet();
            ds.Tables.Add(table);

            using (FileStream stream = new FileStream(_tempFile, FileMode.Open))
            {
                try
                {
                    table.ReadXmlSchema(stream);
                    Assert.False(true);
                }
                catch (ArgumentException ex)
                {
                    // DataTable 'Table1' does not match
                    // to any DataTable in source
                    Assert.Equal(typeof(ArgumentException), ex.GetType());
                    Assert.Null(ex.InnerException);
                    Assert.NotNull(ex.Message);
                    Assert.True(ex.Message.IndexOf("'Table1'") != -1);
                    Assert.Null(ex.ParamName);
                }
            }
        }
开发者ID:dotnet,项目名称:corefx,代码行数:32,代码来源:DataTableTest3.cs

示例3: XmlSchemaTest1

        public void XmlSchemaTest1()
        {
            MakeParentTable();
            //Detach the table from the DataSet
            _dataSet.Tables.Remove(_parentTable);

            //Write
            using (FileStream stream = new FileStream(_tempFile, FileMode.Create))
            {
                _parentTable.WriteXmlSchema(stream);
            }

            //Read
            DataTable table = new DataTable();
            using (FileStream stream = new FileStream(_tempFile, FileMode.Open))
            {
                table.ReadXmlSchema(stream);
            }

            VerifyTableSchema(table, _parentTable.TableName, _parentTable.DataSet);
        }
开发者ID:dotnet,项目名称:corefx,代码行数:21,代码来源:DataTableTest3.cs

示例4: XmlSchemaTest3

        public void XmlSchemaTest3()
        {
            //Write
            MakeParentTable();

            using (FileStream stream = new FileStream(_tempFile, FileMode.Create))
            {
                _parentTable.WriteXmlSchema(stream);
            }

            //Read
            DataTable table = new DataTable();
            using (FileStream stream = new FileStream(_tempFile, FileMode.Open))
            {
                table.ReadXmlSchema(stream);
            }

            VerifyTableSchema(table, _parentTable.TableName, null);
        }
开发者ID:dotnet,项目名称:corefx,代码行数:19,代码来源:DataTableTest3.cs

示例5: ReadXmlSchemeWithScheme

        public void ReadXmlSchemeWithScheme()
        {
            const string xml = @"<CustomElement>
				  <xs:schema id='NewDataSet' xmlns='' xmlns:xs='http://www.w3.org/2001/XMLSchema' xmlns:msdata='urn:schemas-microsoft-com:xml-msdata'>
					<xs:element name='NewDataSet' msdata:IsDataSet='true' msdata:MainDataTable='row' msdata:Locale=''>
					  <xs:complexType>
						<xs:choice minOccurs='0' maxOccurs='unbounded'>
						  <xs:element name='row' msdata:Locale=''>
							<xs:complexType>
							  <xs:sequence>
								<xs:element name='Text' type='xs:string' minOccurs='0' />
							  </xs:sequence>
							</xs:complexType>
						  </xs:element>
						</xs:choice>
					  </xs:complexType>
					</xs:element>
				  </xs:schema>
				</CustomElement>";
            using (var s = new StringReader(xml))
            {
                DataTable dt = new DataTable();
                dt.ReadXmlSchema(s);
                Assert.Equal("row", dt.TableName);
            }
        }
开发者ID:dotnet,项目名称:corefx,代码行数:26,代码来源:DataTableTest.cs

示例6: ReadXmlSchemeWithBadScheme

        public void ReadXmlSchemeWithBadScheme()
        {
            const string xml = @"<CustomElement>
				  <xs:schema id='NewDataSet' xmlns='' xmlns:xs='http://www.w3.org/2001/BAD' xmlns:msdata='urn:schemas-microsoft-com:xml-msdata'>
				  </xs:schema>
				</CustomElement>";
            Assert.Throws<ArgumentException>(() =>
            {
                using (var s = new StringReader(xml))
                {
                    DataTable dt = new DataTable();
                    dt.ReadXmlSchema(s);
                }
            });
        }
开发者ID:dotnet,项目名称:corefx,代码行数:15,代码来源:DataTableTest.cs

示例7: ReadWriteXmlSchemaExp_TableNameConflict

 public void ReadWriteXmlSchemaExp_TableNameConflict()
 {
     DataTable dtw = new DataTable("Table1");
     StringWriter writer1 = new StringWriter();
     dtw.WriteXmlSchema(writer1);
     DataTable dtr = new DataTable("Table2");
     StringReader reader1 = new StringReader(writer1.ToString());
     try
     {
         dtr.ReadXmlSchema(reader1);
         Assert.False(true);
     }
     catch (ArgumentException)
     {
     }
 }
开发者ID:dotnet,项目名称:corefx,代码行数:16,代码来源:DataTableTest.cs

示例8: ReadXmlSchema_2

 public void ReadXmlSchema_2()
 {
     DataTable dt = new DataTable();
     string xmlData = string.Empty;
     xmlData += "<?xml version=\"1.0\"?>";
     xmlData += "<xs:schema id=\"SiteConfiguration\" targetNamespace=\"http://tempuri.org/PortalCfg.xsd\" xmlns:mstns=\"http://tempuri.org/PortalCfg.xsd\" xmlns=\"http://tempuri.org/PortalCfg.xsd\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xmlns:msdata=\"urn:schemas-microsoft-com:xml-msdata\" attributeFormDefault=\"qualified\" elementFormDefault=\"qualified\">";
     xmlData += "<xs:element name=\"SiteConfiguration\" msdata:IsDataSet=\"true\" msdata:EnforceConstraints=\"False\">";
     xmlData += "<xs:complexType>";
     xmlData += "<xs:choice  minOccurs=\"0\" maxOccurs=\"unbounded\">";
     xmlData += "<xs:element name=\"Tab\">";
     xmlData += "<xs:complexType>";
     xmlData += "<xs:sequence>";
     xmlData += "<xs:element name=\"Module\" minOccurs=\"0\" maxOccurs=\"unbounded\">";
     xmlData += "<xs:complexType>";
     xmlData += "<xs:attribute name=\"ModuleId\" form=\"unqualified\" type=\"xs:int\" />";
     xmlData += "</xs:complexType>";
     xmlData += "</xs:element>";
     xmlData += "</xs:sequence>";
     xmlData += "<xs:attribute name=\"TabId\" form=\"unqualified\" type=\"xs:int\" />";
     xmlData += "</xs:complexType>";
     xmlData += "</xs:element>";
     xmlData += "</xs:choice>";
     xmlData += "</xs:complexType>";
     xmlData += "<xs:key name=\"TabKey\" msdata:PrimaryKey=\"true\">";
     xmlData += "<xs:selector xpath=\".//mstns:Tab\" />";
     xmlData += "<xs:field xpath=\"@TabId\" />";
     xmlData += "</xs:key>";
     xmlData += "<xs:key name=\"ModuleKey\" msdata:PrimaryKey=\"true\">";
     xmlData += "<xs:selector xpath=\".//mstns:Module\" />";
     xmlData += "<xs:field xpath=\"@ModuleID\" />";
     xmlData += "</xs:key>";
     xmlData += "</xs:element>";
     xmlData += "</xs:schema>";
     dt.ReadXmlSchema(new StringReader(xmlData));
 }
开发者ID:dotnet,项目名称:corefx,代码行数:35,代码来源:DataTableTest.cs

示例9: WriteXmlSchema_Relations_ForeignKeys

        public void WriteXmlSchema_Relations_ForeignKeys()
        {
            MemoryStream ms1 = null;
            MemoryStream ms2 = null;
            MemoryStream msA = null;
            MemoryStream msB = null;

            DataSet ds1 = new DataSet();

            DataTable table1 = ds1.Tables.Add("Table 1");
            DataTable table2 = ds1.Tables.Add("Table 2");

            DataColumn col1_1 = table1.Columns.Add("col 1", typeof(int));
            DataColumn col1_2 = table1.Columns.Add("col 2", typeof(int));
            DataColumn col1_3 = table1.Columns.Add("col 3", typeof(int));
            DataColumn col1_4 = table1.Columns.Add("col 4", typeof(int));
            DataColumn col1_5 = table1.Columns.Add("col 5", typeof(int));
            DataColumn col1_6 = table1.Columns.Add("col 6", typeof(int));
            DataColumn col1_7 = table1.Columns.Add("col 7", typeof(int));

            DataColumn col2_1 = table2.Columns.Add("col 1", typeof(int));
            DataColumn col2_2 = table2.Columns.Add("col 2", typeof(int));
            DataColumn col2_3 = table2.Columns.Add("col 3", typeof(int));
            DataColumn col2_4 = table2.Columns.Add("col 4", typeof(int));
            DataColumn col2_5 = table2.Columns.Add("col 5", typeof(int));
            DataColumn col2_6 = table2.Columns.Add("col 6", typeof(int));
            DataColumn col2_7 = table2.Columns.Add("col 7", typeof(int));

            ds1.Relations.Add("rel 1",
                new DataColumn[] { col1_1, col1_2 },
                new DataColumn[] { col2_1, col2_2 },
                false);
            ds1.Relations.Add("rel 2",
                new DataColumn[] { col1_3, col1_4 },
                new DataColumn[] { col2_3, col2_4 },
                true);
            table2.Constraints.Add("fk 1",
                new DataColumn[] { col1_5, col1_6 },
                new DataColumn[] { col2_5, col2_6 });
            table1.Constraints.Add("fk 2",
                new DataColumn[] { col2_5, col2_6 },
                new DataColumn[] { col1_5, col1_6 });

            table1.Constraints.Add("pk 1", col1_7, true);
            table2.Constraints.Add("pk 2", col2_7, true);

            ms1 = new MemoryStream();
            ds1.Tables[0].WriteXmlSchema(ms1);
            ms2 = new MemoryStream();
            ds1.Tables[1].WriteXmlSchema(ms2);

            msA = new MemoryStream(ms1.GetBuffer());
            DataTable dtA = new DataTable();
            dtA.ReadXmlSchema(msA);

            msB = new MemoryStream(ms2.GetBuffer());
            DataTable dtB = new DataTable();
            dtB.ReadXmlSchema(msB);

            Assert.Equal(3, dtA.Constraints.Count);
            Assert.Equal(2, dtB.Constraints.Count);

            Assert.True(dtA.Constraints.Contains("pk 1"));
            Assert.True(dtA.Constraints.Contains("Constraint1"));
            Assert.True(dtA.Constraints.Contains("Constraint2"));
            Assert.True(dtB.Constraints.Contains("pk 2"));
            Assert.True(dtB.Constraints.Contains("Constraint1"));
        }
开发者ID:dotnet,项目名称:corefx,代码行数:68,代码来源:DataTableTest.cs

示例10: ReadWriteXmlSchemaExp_NoRootElmnt

 public void ReadWriteXmlSchemaExp_NoRootElmnt()
 {
     MemoryStream ms = new MemoryStream();
     DataTable dtr = new DataTable();
     try
     {
         dtr.ReadXmlSchema(ms);
         Assert.False(true);
     }
     catch (XmlException)
     {
     }
 }
开发者ID:dotnet,项目名称:corefx,代码行数:13,代码来源:DataTableTest.cs

示例11: ReadXmlSchema_ByXmlReader

        public void ReadXmlSchema_ByXmlReader()
        {
            DataSet ds1 = new DataSet();
            ds1.Tables.Add(DataProvider.CreateParentDataTable());
            ds1.Tables.Add(DataProvider.CreateChildDataTable());

            StringWriter sw1 = new StringWriter();
            XmlTextWriter xmlTW1 = new XmlTextWriter(sw1);
            StringWriter sw2 = new StringWriter();
            XmlTextWriter xmlTW2 = new XmlTextWriter(sw2);

            //write xml file, schema only
            ds1.Tables[0].WriteXmlSchema(xmlTW1);
            xmlTW1.Flush();
            ds1.Tables[1].WriteXmlSchema(xmlTW2);
            xmlTW2.Flush();

            StringReader sr1 = new StringReader(sw1.ToString());
            XmlTextReader xmlTR1 = new XmlTextReader(sr1);
            StringReader sr2 = new StringReader(sw2.ToString());
            XmlTextReader xmlTR2 = new XmlTextReader(sr2);

            //copy both data and schema
            //DataSet ds2 = new DataSet ();
            DataTable dt1 = new DataTable();
            DataTable dt2 = new DataTable();

            //ds2.ReadXmlSchema (xmlTR);
            dt1.ReadXmlSchema(xmlTR1);
            dt2.ReadXmlSchema(xmlTR2);

            //check xml schema
            // ReadXmlSchema - Tables count
            //Assert.Equal (ds2.Tables.Count, ds1.Tables.Count);

            // ReadXmlSchema - Tables 0 Col count
            Assert.Equal(ds1.Tables[0].Columns.Count, dt1.Columns.Count);

            // ReadXmlSchema - Tables 1 Col count
            Assert.Equal(ds1.Tables[1].Columns.Count, dt2.Columns.Count);

            //check some colummns types
            // ReadXmlSchema - Tables 0 Col type
            Assert.Equal(ds1.Tables[0].Columns[0].GetType(), dt1.Columns[0].GetType());

            // ReadXmlSchema - Tables 1 Col type
            Assert.Equal(ds1.Tables[1].Columns[3].GetType(), dt2.Columns[3].GetType());

            //check that no data exists
            // ReadXmlSchema - Table 1 row count
            Assert.Equal(0, dt1.Rows.Count);

            // ReadXmlSchema - Table 2 row count
            Assert.Equal(0, dt2.Rows.Count);
        }
开发者ID:dotnet,项目名称:corefx,代码行数:55,代码来源:DataTableTest.cs

示例12: ReadWriteXmlSchema_ByFileName

        public void ReadWriteXmlSchema_ByFileName()
        {
            string sTempFileName1 = Path.Combine(Path.GetTempPath(), "tmpDataSet_ReadWriteXml_43899-1.xml");
            string sTempFileName2 = Path.Combine(Path.GetTempPath(), "tmpDataSet_ReadWriteXml_43899-2.xml");

            DataSet ds1 = new DataSet();
            ds1.Tables.Add(DataProvider.CreateParentDataTable());
            ds1.Tables.Add(DataProvider.CreateChildDataTable());

            ds1.Tables[0].WriteXmlSchema(sTempFileName1);
            ds1.Tables[1].WriteXmlSchema(sTempFileName2);

            DataTable dt1 = new DataTable();
            DataTable dt2 = new DataTable();

            dt1.ReadXmlSchema(sTempFileName1);
            dt2.ReadXmlSchema(sTempFileName2);

            Assert.Equal(ds1.Tables[0].Columns.Count, dt1.Columns.Count);
            Assert.Equal(ds1.Tables[1].Columns.Count, dt2.Columns.Count);
            Assert.Equal(ds1.Tables[0].Columns[0].GetType(), dt1.Columns[0].GetType());
            Assert.Equal(ds1.Tables[1].Columns[3].GetType(), dt2.Columns[3].GetType());
            Assert.Equal(0, dt1.Rows.Count);
            Assert.Equal(0, dt2.Rows.Count);

            File.Delete(sTempFileName1);
            File.Delete(sTempFileName2);
        }
开发者ID:dotnet,项目名称:corefx,代码行数:28,代码来源:DataTableTest.cs

示例13: ReadXmlSchema_ByStream

        public void ReadXmlSchema_ByStream()
        {
            DataSet ds1 = new DataSet();
            ds1.Tables.Add(DataProvider.CreateParentDataTable());
            ds1.Tables.Add(DataProvider.CreateChildDataTable());

            MemoryStream ms1 = new MemoryStream();
            MemoryStream ms2 = new MemoryStream();
            //write xml  schema only
            //ds1.WriteXmlSchema (ms);
            ds1.Tables[0].WriteXmlSchema(ms1);
            ds1.Tables[1].WriteXmlSchema(ms2);

            MemoryStream ms11 = new MemoryStream(ms1.GetBuffer());
            MemoryStream ms22 = new MemoryStream(ms2.GetBuffer());
            //copy schema
            //DataSet ds2 = new DataSet ();
            DataTable dt1 = new DataTable();
            DataTable dt2 = new DataTable();

            //ds2.ReadXmlSchema (ms1);
            dt1.ReadXmlSchema(ms11);
            dt2.ReadXmlSchema(ms22);

            //check xml schema
            // ReadXmlSchema - Tables count
            //Assert.Equal (ds2.Tables.Count, ds1.Tables.Count);

            // ReadXmlSchema - Tables 0 Col count
            Assert.Equal(ds1.Tables[0].Columns.Count, dt1.Columns.Count);

            // ReadXmlSchema - Tables 1 Col count
            Assert.Equal(ds1.Tables[1].Columns.Count, dt2.Columns.Count);

            //check some colummns types
            // ReadXmlSchema - Tables 0 Col type
            Assert.Equal(ds1.Tables[0].Columns[0].GetType(), dt1.Columns[0].GetType());

            // ReadXmlSchema - Tables 1 Col type
            Assert.Equal(ds1.Tables[1].Columns[3].GetType(), dt2.Columns[3].GetType());

            //check that no data exists
            // ReadXmlSchema - Table 1 row count
            Assert.Equal(0, dt1.Rows.Count);

            // ReadXmlSchema - Table 2 row count
            Assert.Equal(0, dt2.Rows.Count);
        }
开发者ID:dotnet,项目名称:corefx,代码行数:48,代码来源:DataTableTest.cs

示例14: XmlSchemaTest7

        public void XmlSchemaTest7()
        {
            DataTable table = new DataTable();

            try
            {
                table.ReadXmlSchema(string.Empty);
                Assert.False(true);
            }
            catch (ArgumentException ex)
            {
                // The URL cannot be empty
                Assert.Equal(typeof(ArgumentException), ex.GetType());
                Assert.Null(ex.InnerException);
                Assert.NotNull(ex.Message);
                //Assert.Equal ("url", ex.ParamName);
            }
        }
开发者ID:dotnet,项目名称:corefx,代码行数:18,代码来源:DataTableTest3.cs

示例15: ReadXmlSchemeWithoutScheme

 public void ReadXmlSchemeWithoutScheme()
 {
     const string xml = @"<CustomElement />";
     using (var s = new StringReader(xml))
     {
         DataTable dt = new DataTable();
         dt.ReadXmlSchema(s);
         Assert.Equal("", dt.TableName);
     }
 }
开发者ID:dotnet,项目名称:corefx,代码行数:10,代码来源:DataTableTest.cs


注:本文中的DataTable.ReadXmlSchema方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。