...

View Full Version : Error with online form



dynasty
01-18-2012, 02:28 PM
Hi all,

I am receiving an error "Object reference not set to an instance of an object" when logging into an online form. As far as I can see, the object has been instantiated and assigned. The error is at "http://www.cbmphiv.com/admin/placements_by_type_by_month.aspx?ptype=R" when using the username "admin" and the password "test". The code in question is as follows:



using System;
using System.Data;
using System.Data.SqlClient;
using NHibernate;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using cbmphiv_dal;

public partial class admin_placements_by_type_by_month : System.Web.UI.Page
{
// this report takes as params:
// 1. A package
// 2. A programming type (Radio/TV)
protected String programmingType = "T";
protected cbmphiv_dal.package package = null;
protected void Page_Load(object sender, EventArgs e)
{
DALHelpers dal = null;
try
{
dal = new DALHelpers();
int pid = -1;
// try to collect our request items.
// get pid.
if (Request["pid"] != null)
pid = Int32.Parse(Request["pid"]);
if (Request["ptype"] != null)
programmingType = Request["ptype"];
// setup title.
if (programmingType == "T")
title_row.Text = "Total Placements, by Programming Type (TV)";
else if (programmingType == "R")
title_row.Text = "Total Placements, by Programming Type (Radio)";
else
title_row.Text = "Total Placements, by Programming Type (All)";
title_row.CssClass = "subheadadmin_title";

// get list of packages.
IList packages = dal.getPackages();
// populate select box with these packages:
if (pid == -1 && packages.Count > 0)
pid = dal.getCurrentPackageId();
select_Package.Items.Clear();
foreach (package p in packages)
{
ListItem litem = new ListItem(p.package_name + ", " + p.start_date.ToShortDateString() + " - " + p.end_date.ToShortDateString(), Request.Url.AbsolutePath + "?pid=" + p.package_id.ToString() + "&ptype=" + programmingType);
if (p.package_id == pid)
litem.Selected = true;
else
litem.Selected = false;
select_Package.Items.Add(litem);
}

// get selected (or default) package.
package = dal.getPackageById(pid);
// now, gather up our broadcasters.
IList broadcasters = dal.getBroadcasters(programmingType);
// now, gather up our items.
IList items = dal.getItems(pid, programmingType);
// gather up a list of item types - alphabetically!
ArrayList item_types = dal.getItemTypes(programmingType);
// figure out how many months we are talking about:
int num_months = rep_utils.getMonths(package.end_date, package.start_date);
// (setup the title row's number of columns)
title_row.ColumnSpan = num_months * item_types.Count + 1;
// first, add a title row.
TableRow row = new TableRow();
TableCell cell = new TableCell();
cell.Text = "Name of Broadcaster";
cell.CssClass = "bodytext_label_title";
cell.ColumnSpan = 1;
row.Cells.Add(cell);

foreach (String s in item_types)
{
cell = new TableCell();
cell.Text = s;
cell.ColumnSpan = num_months;
row.Cells.Add(cell);
cell.CssClass = "bodytext_label";
}
tbl_Main.Rows.Add(row);
// now, add a row for the month labels.
row = new TableRow();
cell = new TableCell();
cell.Text = " ";
row.Cells.Add(cell);
foreach (String s in item_types)
{
for (int i = 0; i < num_months; i++)
{
cell = new TableCell();
cell.Text = rep_utils.monthString(package.start_date.AddMonths(i).Month);
row.Cells.Add(cell);
cell.CssClass = "bodytext_label";
}
}
tbl_Main.Rows.Add(row);
// set up some places to accumulate entries for the totals for each type.
int[,] total_counts = new int[num_months,item_types.Count];
foreach (broadcaster b in broadcasters)
{
row = new TableRow();
cell = new TableCell();
cell.Text = b.broadcaster_name;
cell.CssClass = "broadcaster_name";
row.Cells.Add(cell);
for (int cur_item_type = 0; cur_item_type < item_types.Count; cur_item_type++)
{
string s = (string) item_types[cur_item_type];
// get items of this type.
IList items_of_cur_type = dal.getItems(package.package_id, s);
int[] counts = new int[num_months];
foreach (item i in items_of_cur_type)
{
// prepare sums for each month.
IList broadcaster_entries = dal.getBroadcasterEntries(b.broadcaster_id, i.item_id);
if (broadcaster_entries != null)
{
foreach (broadcaster_entry bEntry in broadcaster_entries)
{
if ((rep_utils.getMonths(bEntry.entry_date, package.start_date) - 1 < counts.Length) &&
(rep_utils.getMonths(bEntry.entry_date, package.start_date) - 1 >= 0))
{
counts[rep_utils.getMonths(bEntry.entry_date, package.start_date) - 1] += bEntry.period1 + bEntry.period2 + bEntry.period3;
total_counts[rep_utils.getMonths(bEntry.entry_date, package.start_date) - 1, cur_item_type] += bEntry.period1 + bEntry.period2 + bEntry.period3;
}
}
}
}
// now, complete the cells
for (int cur_count = 0; cur_count < counts.Length; cur_count++)
{
cell = new TableCell();
cell.Text = counts[cur_count].ToString();
cell.CssClass = "bodytext_values";
row.Cells.Add(cell);
}
}
tbl_Main.Rows.Add(row);
}
// now, add the seperator row.
row = new TableRow();
cell = new TableCell();
row.Height = 5;
cell.Text = " ";
cell.CssClass = "bodytext_row_separater";
cell.ColumnSpan = num_months * item_types.Count + 1;
row.Cells.Add(cell);
tbl_Main.Rows.Add(row);
// now, add rows for total and average.
// total
row = new TableRow();
cell = new TableCell();
cell.Text = "Total Placements";
cell.CssClass = "broadcaster_name";
row.Cells.Add(cell);
for (int cur_item_type = 0; cur_item_type < item_types.Count; cur_item_type++)
{
// now, complete the cells
for (int cur_count = 0; cur_count < num_months; cur_count++)
{
cell = new TableCell();
cell.Text = total_counts[cur_count, cur_item_type].ToString();
cell.CssClass = "bodytext_values";
row.Cells.Add(cell);
}
}
tbl_Main.Rows.Add(row);
}
catch (Exception exception)
{
throw new Exception(exception.Message, exception);
}
finally
{
dal.close();
}
}
}


It is running on an IIS 7 server.

alykins
01-18-2012, 11:20 PM
what line is it breaking on? whole error message is helpful

dynasty
01-19-2012, 01:55 AM
Hello alykins. Thanks for your reply. It is breaking at line 183:


finally
{
dal.close();
}


I have attached a .pdf file showing the error message.

alykins
01-19-2012, 04:14 AM
whatever that class is (I presume you wrote it, but if not then I would talk to whomever wrote it for guidance) is where you are having issues- I will say though that all the occurrences of dal had a dal.get something... I saw nothing indicative of a connection where you would need the method .Close() ... also does that class even support that method? *I guess it would or you would have had compilation errors.... idk- without seeing that class lib it's hard to say-

dynasty
01-19-2012, 02:08 PM
Thanks for your help alykins. The class library seems to be a .dll file. I will try to reach the developer about it. Thanks again.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum