473,395 Members | 1,689 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

XmlDataDocument error with DataSet relationships set

I have a dataset.



I fill it with two recordsets from SQL queries.

Tables are called tblPlanFYSpendingStage, tblSpendingStage.



I then define the relationships between the two.



So far everything is fine. However, when I attempt to instantiate a new XmlDataDocument using the dataset I get an "Object reference not set to an instance of an object" exception.



I have another set of relationships that are almost identical and that works fine. Any thoughts?



Here is the code and error:



***************************************





objQueries.tblPlanFYSpendingStage(dstDS);
objQueries.tblSpendingStage(dstDS);

objQueries.DefineRelationships(dstDS);
xdForm1370Data = new XmlDataDocument(dstDS); <<<<<<<<<throws error here

public void tblPlanFYSpendingStage(DataSet dstDS)
{
OleDbDataAdapter dadBPA;

string sQuery;

sQuery = "SELECT " +
" tblPlanFYSpendingStage.PlanFYSpendingStageID as PlanFYSpendingStageID, " +
" tblPlanFYSpendingStage.PlanID as PlanID, " +
" tblPlanFYSpendingStage.SpendingStageID as SpendingStageID, " +
" tblPlanFYSpendingStage.FYOffset as FYOffset, " +
" tblPlanFYSpendingStage.Cap as Cap, " +
" tblPlanFYSpendingStage.Exp as Exp " +
"FROM tblPlanFYSpendingStage " +
"WHERE " +
" tblPlanFYSpendingStage.PlanID=" + PlanID + " " +
"ORDER BY " +
" tblPlanFYSpendingStage.SpendingStageID, tblPlanFYSpendingStage.FYOffset" +
";";

// open up the connection
conBPA = new OleDbConnection(sConn);

// get record set
dadBPA = new OleDbDataAdapter(sQuery, conBPA);

// add to data set
dadBPA.Fill(dstDS, Constants.PlanFYSpendingStage);

// set primary key
dstDS.Tables[Constants.PlanFYSpendingStage].PrimaryKey = new DataColumn[] {dstDS.Tables[Constants.PlanFYSpendingStage].Columns["PlanFYSpendingStageID"]};

conBPA.Close();

conBPA.Dispose();
dadBPA.Dispose();
}
public void tblSpendingStage(DataSet dstDS)
{
OleDbDataAdapter dadBPA;

string sQuery;

sQuery = "SELECT " +
" tblSpendingStage.SpendingStageID as SpendingStageID, " +
" tblSpendingStage.SpendingStage as SpendingStage, " +
" tblSpendingStage.SpendingCat as SpendingCat, " +
" tblSpendingStage.Tag as Tag, " +
" tblSpendingStage.CapAlias as CapAlias, " +
" tblSpendingStage.ExpAlias as ExpAlias " +
"FROM tblSpendingStage " +
"ORDER BY " +
" tblSpendingStage.Sort" +
";";

// open up the connection
conBPA = new OleDbConnection(sConn);

// get record set
dadBPA = new OleDbDataAdapter(sQuery, conBPA);

// add to data set
dadBPA.Fill(dstDS, Constants.SpendingStage);

// set primary key
dstDS.Tables[Constants.SpendingStage].PrimaryKey = new DataColumn[] {dstDS.Tables[Constants.SpendingStage].Columns["SpendingStageID"]};

conBPA.Close();

conBPA.Dispose();
dadBPA.Dispose();
}

public void DefineRelationships(DataSet dstDS)
{
dstDS.Relations.Add("SpendingStage_to_PlanFYSpendi ngStage",
dstDS.Tables[Constants.SpendingStage].Columns["SpendingStageID"],
dstDS.Tables[Constants.PlanFYSpendingStage].Columns["SpendingStageID"]);
dstDS.Relations["SpendingStage_to_PlanFYSpendingStage"].Nested = true; // allows nested XML

}

******************************************

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

Line 87:
Line 88: xdForm1370Data = new XmlDataDocument(dstDS);
Line 89:
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.]
System.Xml.XmlDataDocument.OnNestedParentChange(Da taRow child, XmlBoundElement childElement, DataColumn childCol)
System.Xml.XmlDataDocument.OnAddRow(DataRow row)
System.Xml.XmlDataDocument.LoadTreeFromDataSet(Dat aSet ds)
System.Xml.XmlDataDocument.Bind(Boolean fLoadFromDataSet)
System.Xml.XmlDataDocument.Init(DataSet ds)
System.Xml.XmlDataDocument..ctor(DataSet dataset)
BPA.for1370.BuildSections() in c:\inetpub\wwwroot\bpa\form1370.aspx.cs:88
BPA.for1370.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\bpa\form1370.aspx.cs:69
System.Web.UI.Control.OnLoad(EventArgs e)
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Page.ProcessRequestMain()


Nov 18 '05 #1
0 1414

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: gilly3 | last post by:
Reposting to a more relevant group. I am passing a generic dataset into a new XMLDataDocument and then parsing the XML with XSLT. The idea being that I can parse any dataset with the same xslt,...
2
by: James Ankrom | last post by:
Why does this fail? Dim relResources As New Data.DataRelation("Application_Resources", ..Tables("User_Applications").Columns("Application_id"),...
3
by: Derrick | last post by:
I am reading in xml files that equate to sql tables, via XmlDataDocument, and then operating on the DataSet. With the most simple app that just loads the xml doc, I see the memory footprint of the...
2
by: deko | last post by:
I create an XmlDataDocument Dataset when the main form of my WinForms app opens. The user will make changes to the Dataset, and then those changes should be saved to the XML file when the code...
4
by: Adrian Meyer | last post by:
Hi, On the server I code the following web service: ))] public XmlDataDocument GetTypedXmlDataDocument() { sqlDataAdapter1.Fill(typedDataSet1); XmlDataDocument dataDoc
3
by: jmagaram | last post by:
I have a DataSet I want to work with as Xml using XmlDataDocument. I can't figure out how to query the resultant Xml using XPath. From the following XML below, what XPath query will return the list...
1
by: JD | last post by:
I have a DataGridView with a DataSet as DataSource. The user can update the contents of the DataGridView, and then click on a Save button to save the data to an XML file. When they click on...
2
by: ERingmae | last post by:
Hi, The environment is .NET 2.0, the language is C# and the problem is reading XSD file with xs:redefine section correctly to a XMLDataDocument.DataSet. What I am trying to do: I am trying...
3
by: david.juffermans | last post by:
Hi, I have a problem reading xml into a dataset using the XmlDataDocument. In a test project, I created the following xml file: <?xml version="1.0" standalone="yes"?> <Customer>...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.