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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Relate Datatables in a Dataset

Status
Not open for further replies.

TonyFoo

Programmer
Jul 2, 2008
21
CA
Hi All,

I have been recieving a null pointer exception (SOAP Exception) from a web service I am calling that returns a complete dataset. Here is the web service:

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;

namespace LookupAllProductData
{

[WebService(Namespace = "]
public class LoadAllProductData : System.Web.Services.WebService
{

[WebMethod]
public DataSet Products()
{

SmartMartSystem.SmartMart A = new SmartMartSystem.SmartMart();
DataSet productsDataSet = new DataSet();
productsDataSet = A.lookupAllProducts();
productsDataSet = relateDataTables(productsDataSet);
return productsDataSet;

}
private DataSet relateDataTables(DataSet ds)
{
if (ds.Tables.Count < 1)
{
throw new Exception("Fxxx");
}
else
{

ds.Relations.Add("FamiliesToDepartments",
ds.Tables["Families"].Columns["FamilyId"],
ds.Tables["Departments"].Columns["FamilyId"], true);
ds.Relations["FamiliesToDepartments"].Nested = true;
ds.Relations.Add("DepartmentsToCategories",
ds.Tables["Departments"].Columns["DepartmentId"],
ds.Tables["Categories"].Columns["DepartmentId"], true);
ds.Relations["DepartmentsToCategories"].Nested = true;
ds.Relations.Add("CategoriesToSubCategories",
ds.Tables["Categories"].Columns["CategoryId"],
ds.Tables["Subcategories"].Columns["CategoryId"], true);
ds.Relations["CategoriesToSubcategories"].Nested = true;
ds.Relations.Add("SubcategoriesToProducts",
ds.Tables["Subcategories"].Columns["SubcategoryId"],
ds.Tables["Products"].Columns["SubcategoryId"], true);
ds.Relations["SubcategoriesToProducts"].Nested = true;
}
return ds;
}
}
}
 
so you know the type of exception. what about the actual exception message and stack trace? this will tell you were to start debugging.

If your using datasets. this scenario should use a strongly typed dataset instead of a generic runtime dataset. it just makes sense in this scenario.

the logic within relateDataTables(DataSet) doesn't make sense.
1. your only checking for < 1 table when the logic requires at least 8 specific tables.
2. You should throw a much more specific exception then Exception. Either a custom exception you define, or an Exception related to DataSets.
3. The message is also useless "Fxxx" doesn't means anything. if this is a flag for a catching block, then roll your own exception with a Property of string Flag {get;} or something. then catch this specific exception in the client code

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top