Hi,
I create a typed dataset which has 2 tables Order and OrderDetail, I also build relation between Order and OrderDetail as nest which means one order row include multiple orderdetail rows. But when I load data from database to this typed dataset, it looks like Fill() method cannot load data like what I define in typed dataset. When I drill down order row, it doesn't include orderdetail rows. I list typed dataset xsd and the code I load from database.
< xml version="1.0" encoding="utf-8" > <xs:schema id="TestDS" targetNamespace=" http://www.hide-link.com/ " elementFormDefault="qualified" attributeFormDefault="qualified" xmlns=" http://www.hide-link.com/ " xmlns:mstns=" http://www.hide-link.com/ " xmlns:xs=" http://www.hide-link.com/ " xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> <xs:element name="TestDS" msdata:IsDataSet="true"> <xs:complexType> <xs:choice maxOccurs="unbounded"> <xs:element name="Order" > <xs:complexType> <xs:sequence> <xs:element name="OrderId" type="xs:int" minOccurs="0" /> <xs:element name="OrderName" type="xs:string" minOccurs="0" /> <xs:element name="OrderDetail"> <xs:complexType> <xs:sequence> <xs:element name="OrderDetailId" type="xs:int" minOccurs="0" /> <xs:element name="OrderDetailName" type="xs:string" minOccurs="0" /> </xs:sequence> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element> </xs:choice> </xs:complexType> <xs:key name="TestDS_Order_Key"> <xs:selector xpath=".//mstns:Order" /> <xs:field xpath="mstns:OrderId" /> </xs:key> <xs:key name="TestDS_OrderDetail_Key"> <xs:selector xpath=".//mstns:OrderDetail" /> <xs:field xpath="mstns:OrderDetailId" /> </xs:key> </xs:element> </xs:schema>
Dim dsn As String = "data source=(local);initial catalog=TestDB;User id=sa;password=1234" Dim conn As SqlConnection Dim da As SqlDataAdapter Dim ds As New TestDS 'DataSet Dim sql As String Try conn = New SqlConnection(dsn)
sql = "select * from [order]" da = New SqlDataAdapter(sql, conn) da.Fill(ds, "order")
sql = "select * from orderdetail" da = New SqlDataAdapter(sql, conn) da.Fill(ds, "orderdetail")
Catch ex As Exception MessageBox.Show(ex.Message) Finally If Not conn Is Nothing Then conn.Close() End If End Try
.NET Development32
|