Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

No relations in DataSet...

Status
Not open for further replies.

steverbs

Programmer
Jul 17, 2003
253
0
0
GB
Hi all.

I have the following DataSet:
Code:
	<xs:element name="Structure" msdata:IsDataSet="true">
		<xs:complexType>
			<xs:choice maxOccurs="unbounded">
				<xs:element name="INF_COMP">
					<xs:complexType>
						<xs:sequence>
							<xs:element name="PK" type="xs:int" />
							<xs:element name="FK" type="xs:int" minOccurs="0" />
							<xs:element name="Field1" type="xs:string" minOccurs="0" />
							<xs:element name="Field2" type="xs:dateTime" minOccurs="0" />
						</xs:sequence>
					</xs:complexType>
				</xs:element>
				<xs:element name="INF_PERS">
					<xs:complexType>
						<xs:sequence>
							<xs:element name="PK" type="xs:int" />
							<xs:element name="FK" type="xs:int" minOccurs="0" />
							<xs:element name="Field1" type="xs:string" minOccurs="0" />
							<xs:element name="Field2" type="xs:dateTime" minOccurs="0" />
							<xs:element name="Field3" type="xs:string" minOccurs="0" />
						</xs:sequence>
					</xs:complexType>
				</xs:element>
				<xs:element name="INF_FIN">
					<xs:complexType>
						<xs:sequence>
							<xs:element name="PK" type="xs:int" />
							<xs:element name="FK" type="xs:int" minOccurs="0" />
							<xs:element name="Field1" type="xs:dateTime" minOccurs="0" />
							<xs:element name="Field2" type="xs:string" minOccurs="0" />
							<xs:element name="Field3" type="xs:dateTime" minOccurs="0" />
						</xs:sequence>
					</xs:complexType>
				</xs:element>
			</xs:choice>
		</xs:complexType>
		<xs:key name="PK_COMP_PK" msdata:PrimaryKey="true">
			<xs:selector xpath=".//mstns:INF_COMP" />
			<xs:field xpath="mstns:PK" />
		</xs:key>
		<xs:key name="PK_PERS_PK" msdata:PrimaryKey="true">
			<xs:selector xpath=".//mstns:INF_PERS" />
			<xs:field xpath="mstns:PK" />
		</xs:key>
		<xs:key name="PK_FIN_PK" msdata:PrimaryKey="true">
			<xs:selector xpath=".//mstns:INF_FIN" />
			<xs:field xpath="mstns:PK" />
		</xs:key>
		<xs:keyref name="RLTN_COMP_PERS" refer="PK_COMP_PK" msdata:ConstraintOnly="true" msdata:AcceptRejectRule="None"
			msdata:DeleteRule="Cascade" msdata:UpdateRule="Cascade">
			<xs:selector xpath=".//mstns:INF_PERS" />
			<xs:field xpath="mstns:FK" />
		</xs:keyref>
		<xs:keyref name="RLTN_COMP_FIN" refer="PK_COMP_PK" msdata:ConstraintOnly="true" msdata:AcceptRejectRule="None"
			msdata:DeleteRule="Cascade" msdata:UpdateRule="None">
			<xs:selector xpath=".//mstns:INF_FIN" />
			<xs:field xpath="mstns:FK" />
		</xs:keyref>
		<xs:keyref name="COMP_PARENTCOMP" refer="PK_COMP_PK" msdata:ConstraintOnly="true" msdata:AcceptRejectRule="None"
			msdata:DeleteRule="SetNull" msdata:UpdateRule="SetNull">
			<xs:selector xpath=".//mstns:INF_COMP" />
			<xs:field xpath="mstns:FK" />
		</xs:keyref>
	</xs:element>
Now, for some reason if I instantiate this (not filling it) DataSet (ds = New Structure), I can get to all three tables by using ds.Tables, but ds.Relations.Count = 0, even though there are three table references set. I need to be able to get the relationship information from this DataSet, so what am I doing wrong?

Any help is greatly appreciated.

Regards.

Stephen.
 
OK. I could really do with some help here as now I've found that the dataset won't even fill. If I have just a basic Table which I drag onto the DataSet schema designer from the server explorer and then try to fill the dataset from the same table, it won't fill. the dataAdapter.Fill method returns 1, but ds.Tables(0).Rows.Count returns 0. Here is the code:
Code:
        Dim ds As Structure = New Structure
        Dim conn As SqlClient.SqlConnection = New SqlClient.SqlConnection(Database.Manager.ConnectionString)
        Dim comm As SqlClient.SqlCommand = New SqlClient.SqlCommand("SELECT TOP 1 INF_COMP.* FROM INF_COMP;", conn)
        Dim adapter As New SqlClient.SqlDataAdapter(comm)

        conn.Open()
        adapter.Fill(ds)
        conn.Close()

Now, if I change the code to use just a basic DataSet: "Dim ds As DataSet = New DataSet", it works just fine! The only problem being that I need the Table names & Relations etc loaded into the dataset before I fill it and doing it with generic DataSets doesn't fill the table names.

Your help here would be wortha gold mine to me as I am under alot of pressure and this just isn't going that well.

Thank you.

Stephen.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top