听上去不对,DataTable是可以单独存在的,他们也许在讨论Web Service的传输问题吧,因为DataTable对象目前的实现是不能传的﹐而DataSet则可以

解决方案 »

  1.   


    其实个人觉得你不必要去理会这些,看技术书籍有时就需要不求甚解。到后来你自然知道了。
    也有可能书上写错了。物理的DataTable对象是不能单独存在的,它必须是DataSet的一部分。这句话可能是说,就算你在程序上只有创建DataTable的代码,其实内部也相应创建了一个
    DataSet.如: DataTable dt = new DataTable();你可以通过:dt.DataSet; 访问DataSet
      

  2.   

    所谓的物理就是不虚有的!你建的对象就是虚有的,序列化之后就是物理存在了!也就是说DataTable is Disable to Serialization如果想将DataTable 序列化 就必须将DataTable作为DataSet的一部分序列化鱼只能在水里游
      

  3.   

    TO:XINYULOU 
       你好,能详细的说一下DataTable序列化是什么吗?
      

  4.   

    要序列化DataTable就只能自己扩展具体的可以查看msdn帮助
    ------------------------------------------
    重写编码的 SOAP XML 序列化
    重写将对象序列化为 SOAP 消息的 XML 序列化的过程类似于重写标准 XML 序列化的过程。(有关重写标准 XML 系列化的详细信息,请参见重写 XML 序列化。)
    重写将对象序列化为 SOAP 消息的序列化 
    创建 SoapAttributeOverrides 类的实例。 
    为每个正被序列化的类成员创建一个 SoapAttributes。 
    根据需要,为正被序列化的成员创建一个或多个影响 XML 序列化的特性(有关列表,请参见“控制编码的 SOAP 序列化的属性”)的实例。 
    将 SoapAttributes 的适当属性设置为步骤 3 中所创建的特性。 
    将 SoapAttributes 添加到 SoapAttributeOverrides。 
    使用 SoapAttributeOverrides 创建 XmlTypeMapping。使用 SoapReflectionImporter.ImportTypeMapping 方法。 
    使用 XmlTypeMapping 创建 XmlSerializer。 
    序列化或反序列化该对象。 
    下面的示例以两种方式序列化一个文件:第一种不重写 XmlSerializer 类的行为,而第二种则是通过重写该行为来序列化。该示例包含一个带有若干成员的名为 Group 的类。各种属性(如 SoapElementAttribute)都已应用于类成员。当用 SerializeOriginal 方法序列化该类时,这些属性控制 SOAP 消息内容。当调用 SerializeOverride 方法时,通过创建各种特性并(根据需要)将 SoapAttributes 的属性设置为这些特性,可以重写 XmlSerializer 的行为。
    [C#]
    using System;
    using System.IO;
    using System.Xml;
    using System.Xml.Serialization;
    using System.Xml.Schema;public class Group
    {
        [SoapAttribute (Namespace = "http://www.cpandl.com")]
        public string GroupName;
        
        [SoapAttribute(DataType = "base64Binary")]
        public Byte [] GroupNumber;    [SoapAttribute(DataType = "date", AttributeName = "CreationDate")]
        public DateTime Today;
        [SoapElement(DataType = "nonNegativeInteger", ElementName = "PosInt")]
        public string PostitiveInt;
        // This is ignored when serialized unless it is overridden.
        [SoapIgnore] 
        public bool IgnoreThis;    public GroupType Grouptype;
        
        [SoapInclude(typeof(Car))]
        public Vehicle myCar(string licNumber)
        {
            Vehicle v;
            if(licNumber == "")
                {
                    v = new Car();
                v.licenseNumber = "!!!!!!";
            }
            else
            {
                v = new Car();
                v.licenseNumber = licNumber;
            }
            return v;
        }
    }
      

  5.   

    public abstract class Vehicle
    {
        public string licenseNumber;
        public DateTime makeDate;
    }public class Car: Vehicle
    {
    }public enum GroupType
    {
        // These enums can be overridden.
        small,
        large
    }
        
    public class Run
    {
        public static void Main()
        {
            Run test = new Run();
            test.SerializeOriginal("SoapOriginal.xml");
            test.SerializeOverride("SoapOverrides.xml");
            test.DeserializeOriginal("SoapOriginal.xml");
            test.DeserializeOverride("SoapOverrides.xml");
        
        }
        public void SerializeOriginal(string filename)
        {
            // Creates an instance of the XmlSerializer class.
            XmlTypeMapping myMapping = 
            (new SoapReflectionImporter().ImportTypeMapping(
            typeof(Group)));
            XmlSerializer mySerializer =  
            new XmlSerializer(myMapping);        // Writing the file requires a TextWriter.
            TextWriter writer = new StreamWriter(filename);        // Creates an instance of the class that will be serialized.
            Group myGroup = new Group();        // Sets the object properties.
            myGroup.GroupName = ".NET";        Byte [] hexByte = new Byte[2]{Convert.ToByte(100),
            Convert.ToByte(50)};
            myGroup.GroupNumber = hexByte;        DateTime myDate = new DateTime(2002,5,2);
            myGroup.Today = myDate;        myGroup.PostitiveInt= "10000";
            myGroup.IgnoreThis=true;
            myGroup.Grouptype= GroupType.small;
            Car thisCar =(Car)  myGroup.myCar("1234566");        // Prints the license number just to prove the car was created.
            Console.WriteLine("License#: " + thisCar.licenseNumber + "\n");        // Serializes the class, and closes the TextWriter.
            mySerializer.Serialize(writer, myGroup);
            writer.Close();
        }    public void SerializeOverride(string filename)
        {
            // Creates an instance of the XmlSerializer class
            // that overrides the serialization.
            XmlSerializer overRideSerializer = CreateOverrideSerializer();        // Writing the file requires a TextWriter.
            TextWriter writer = new StreamWriter(filename);        // Creates an instance of the class that will be serialized.
            Group myGroup = new Group();        // Sets the object properties.
            myGroup.GroupName = ".NET";        Byte [] hexByte = new Byte[2]{Convert.ToByte(100),
            Convert.ToByte(50)};
            myGroup.GroupNumber = hexByte;        DateTime myDate = new DateTime(2002,5,2);
            myGroup.Today = myDate;
            myGroup.PostitiveInt= "10000";
            myGroup.IgnoreThis=true;
            myGroup.Grouptype= GroupType.small;
            Car thisCar =(Car)  myGroup.myCar("1234566");        // Serializes the class, and closes the TextWriter.
            overRideSerializer.Serialize(writer, myGroup);
             writer.Close();
        }    public void DeserializeOriginal(string filename)
        {
            // Creates an instance of the XmlSerializer class.
            XmlTypeMapping myMapping = 
            (new SoapReflectionImporter().ImportTypeMapping(
            typeof(Group)));
            XmlSerializer mySerializer =  
            new XmlSerializer(myMapping);        TextReader reader = new StreamReader(filename);        // Deserializes and casts the object.
            Group myGroup; 
            myGroup = (Group) mySerializer.Deserialize(reader);        Console.WriteLine(myGroup.GroupName);
            Console.WriteLine(myGroup.GroupNumber[0]);
            Console.WriteLine(myGroup.GroupNumber[1]);
            Console.WriteLine(myGroup.Today);
            Console.WriteLine(myGroup.PostitiveInt);
            Console.WriteLine(myGroup.IgnoreThis);
            Console.WriteLine();
        }    public void DeserializeOverride(string filename)
        {
            // Creates an instance of the XmlSerializer class.
            XmlSerializer overRideSerializer = CreateOverrideSerializer();
            // Reading the file requires a TextReader.
            TextReader reader = new StreamReader(filename);        // Deserializes and casts the object.
            Group myGroup; 
            myGroup = (Group) overRideSerializer.Deserialize(reader);        Console.WriteLine(myGroup.GroupName);
            Console.WriteLine(myGroup.GroupNumber[0]);
            Console.WriteLine(myGroup.GroupNumber[1]);
            Console.WriteLine(myGroup.Today);
            Console.WriteLine(myGroup.PostitiveInt);
            Console.WriteLine(myGroup.IgnoreThis);
        }    private XmlSerializer CreateOverrideSerializer()
        {
            SoapAttributeOverrides mySoapAttributeOverrides = 
            new SoapAttributeOverrides();
            SoapAttributes soapAtts = new SoapAttributes();        SoapElementAttribute mySoapElement = new SoapElementAttribute();
            mySoapElement.ElementName = "xxxx";
            soapAtts.SoapElement = mySoapElement;
            mySoapAttributeOverrides.Add(typeof(Group), "PostitiveInt", 
            soapAtts);        // Overrides the IgnoreThis property.
            SoapIgnoreAttribute myIgnore = new SoapIgnoreAttribute();
            soapAtts = new SoapAttributes();
            soapAtts.SoapIgnore = false;      
            mySoapAttributeOverrides.Add(typeof(Group), "IgnoreThis", 
            soapAtts);        // Overrides the GroupType enumeration.
            soapAtts = new SoapAttributes();
            SoapEnumAttribute xSoapEnum = new SoapEnumAttribute();
            xSoapEnum.Name = "Over1000";
            soapAtts.SoapEnum = xSoapEnum;        // Adds the SoapAttributes to the 
            // mySoapAttributeOverridesrides.
            mySoapAttributeOverrides.Add(typeof(GroupType), "large", 
            soapAtts);        // Creates a second enumeration and adds it.
            soapAtts = new SoapAttributes();
            xSoapEnum = new SoapEnumAttribute();
            xSoapEnum.Name = "ZeroTo1000";
            soapAtts.SoapEnum = xSoapEnum;
            mySoapAttributeOverrides.Add(typeof(GroupType), "small", 
            soapAtts);        // Overrides the Group type.
            soapAtts = new SoapAttributes();
            SoapTypeAttribute soapType = new SoapTypeAttribute();
            soapType.TypeName = "Team";
            soapAtts.SoapType = soapType;
            mySoapAttributeOverrides.Add(typeof(Group),soapAtts);        // Creates an XmlTypeMapping that is used to create an instance 
            // of the XmlSerializer class. Then returns the XmlSerializer.
            XmlTypeMapping myMapping = (new SoapReflectionImporter(
            mySoapAttributeOverrides)).ImportTypeMapping(typeof(Group));
        
            XmlSerializer ser = new XmlSerializer(myMapping);
            return ser;
        }
    }
      

  6.   

    请问你们用的是哪个版本?我用的是1.1的,DataSet和DataTable都是从类MarshalByValueComponent派生的,那就应该都可以序列化啊!做Web Service时,为什么只能用DataSet作传输呢!谢谢!