XmlDataDocument error with DataSet relationships set

S

Steve

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_PlanFYSpendingStage",
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(DataRow child, XmlBoundElement childElement, DataColumn childCol)
System.Xml.XmlDataDocument.OnAddRow(DataRow row)
System.Xml.XmlDataDocument.LoadTreeFromDataSet(DataSet 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()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top