C# .NET - Column 'ServiceId' does not belong to table Table.

Asked By Daniel on 12-Oct-12 11:21 AM
Hi! I have a menu which display data from database like ebay menu or other e-commerce site.Then I want that when someone click on a link(ex:Apparel) the page should redirect to everything related to apparel.brief is like all e-commerce site.When trying to do that I am getting this error:
<<Column 'ServiceId' does not belong to table Table.>>
this the code I am using to do that:
01.protected void Page_Load(object sender, EventArgs e)
02.   {
03.   if (!IsPostBack)
04.     {
05.       this.Title = Request["name"] != null ? HelperFunctions.ReplaceBackSpecialCharacter(Request["name"].ToString()) : string.Empty;
06.       
07.       ServiceInfo _ServiceInfo = new ServiceInfo();
08.       _ServiceInfo.UserId = Session["UserId"] != null ? Convert.ToInt32(Session["UserId"]) : 0;
09.      if ((Request["Type"] != null && Request["Type"].ToString().ToLower().Equals("subcategory")) || Request["ctypeid"] != null)
10.       {
11.         if (Request["type"] != null && Request["type"].ToString().ToLower().Equals("subcategory"))
12.           _ServiceInfo.SubCategoryId = Request["Id"] != null ? Convert.ToInt32(Request["Id"]) : 0;
13.         else
14.           _ServiceInfo.SubCategoryId = 0;
15.           _ServiceInfo.CategoryId = Request["ctypeid"] != null ? Convert.ToInt32(Request["ctypeid"]) : 0;
16.           _ServiceInfo.SearchText = Request["searchtext"] != null ? Request["SearchText"] : string.Empty;
17.       }
18.      else if (Request["Type"] != null && Request["Type"].ToString().ToLower().Equals("category"))
19.      {
20.        _ServiceInfo.CategoryId = Convert.ToInt32(Request["Id"]);
21.         LoadServices(_ServiceInfo.GetByServiceCategoryId().Tables[0]);
22. 
23.      }
24.      
25.     }
26.   }
27. 
28.   private void LoadServices(DataTable dt)
29.   {
30.     if (dt.Rows.Count > 0)
31.     {
32.       foreach (DataRow dr in dt.Rows)
33.       {
34.         ServiceList.Text += string.Format("<div class=\"product-wrapper\" id=\"{0}\">", dr["ServiceId"]);
35.         ServiceList.Text += string.Format("<div class=\"imgwrapper\"><img width=\"135\" alt=\"{0}\" src=\"{1}\" /></div>", Resources.Language.NoPreview, HelperFunctions.GetAbsolutePath(this.Page, string.Format("Images/Member/{0}/{1}", dr["ServiceId"], dr["NormalImage"])));
36.         ServiceList.Text += string.Format("<div class='product-info-wrapper'><h4 class='product-name'>{0}</h4>", HelperFunctions.ReplaceIfEmpty(dr["FServiceName"].ToString(), dr["ServiceName"].ToString()));
37.         ServiceList.Text += "</div>";
38.         ServiceList.Text += string.Format("<div class=\"desc std\">{0}</div>", dr["FDescription"]);//<a class=\"link-learn\"  href=\"#\">Learn More</a>
39. 
40.         ServiceList.Text += "<ul class='other-links'>";
41.         ServiceList.Text += string.Format("<li><a href=\"{0}.aspx\" class='compare'><span>{1}</span></a></li>", HelperFunctions.GetAbsolutePath(this.Page, "Service/" + dr["ServiceId"] + "/" + HelperFunctions.ReplaceSpecialCharacter(HelperFunctions.ReplaceIfEmpty(dr["FServiceName"].ToString(), dr["ServiceName"].ToString()))), Resources.Language.ViewDetails);
42. 
43. 
44. 
45.         ServiceList.Text += string.Format("<li><a class='email' href=\"{0}\" style='margin-left:3px;'>{1}</a></li>", HelperFunctions.GetAbsolutePath(this.Page, "ContactSupplier.aspx?sid=" + dr["SupplierId"]) + "&pid=" + dr["ProductId"], Resources.Language.ContactSupplier);
46. 
47.         ServiceList.Text += "</ul>";
48.         ServiceList.Text += "</div></div>";
49.       }
50.     }
51.     else
52.       HelperFunctions.ShowMessageToUser(MessageWrapper, Resources.Language.ServiceNotFound, HelperFunctions.MessageType.Notice);
53. 
54.   } I am getting the error on the line 34.By the way GetByServiceCategoryId() return a Dataset. Please can someone help. 34.    
Robbe Morris replied to Daniel on 12-Oct-12 11:38 AM
Check your SQL.  Make sure ServiceId is spelled right and that is in there.  You can also iterate through the .Columns collection of the DataTable to what columns it has.