Deng Yi's profileThought WalkerPhotosBlogListsMore Tools Help

Blog


    December 25

    使用类型化DataSet需要注意DataTableName

    使用类型化的DataSet时,DataAdapter.Fill()方法里面的TableName必须和生成类型化DataSet所使用的xsd文件中定义的一样。否则得不到数据。

    例如:

    在xsd文件中:

    <?xml version="1.0" standalone="yes"?>
    <xs:schema id="UserDepartRoleDataSet" xmlns="" xmlns:codegen="urn:schemas-microsoft-com:xml-msprop" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
    <xs:element name="UserDepartRoleDataSet" msdata:IsDataSet="true" msdata:Locale="zh-CN">
    <xs:complexType>
    <xs:choice maxOccurs="unbounded">
    <xs:element name="UserDepartRole">
    <xs:complexType>
    <xs:sequence>
    <xs:element name="USERID" type="xs:string" minOccurs="0" />
    <xs:element name="ROLEID" type="xs:string" minOccurs="0" />
    <xs:element name="DEPARTID" type="xs:string" codegen:nullValue="" minOccurs="0" />
    </xs:sequence>
    </xs:complexType>
    </xs:element>
    </xs:choice>
    </xs:complexType>
    </xs:element>
    </xs:schema>

    在调用时

    UserDepartRoleDataSet ds = new UserDepartRoleDataSet();

    adapter.Fill(ds, "UserDepartRole");

    必须注意这一点。