Null Referance Exception

G

Guest

I keep getting the following exception error:

Object reference not set to an instance of an object.
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 215: clubdg.DataBind();
Line 216:
Line 217: concat.DataSource=dsclub;
Line 218: concat.DataMember=dsclub.Tables["ConCat"].ToString();
Line
219: concat.DataTextField=dsclub.Tables["ConCat"].Columns["Catagory"].ToString();


Source File: c:\inetpub\wwwroot\sonar3\secured\usergrid.aspx.cs Line: 217

Stack Trace:


[NullReferenceException: Object reference not set to an instance of an
object.]
Sonar3.Secured.UserGrid.BindData() in
c:\inetpub\wwwroot\sonar3\secured\usergrid.aspx.cs:217
Sonar3.Secured.UserGrid.Page_Load(Object sender, EventArgs e) in
c:\inetpub\wwwroot\sonar3\secured\usergrid.aspx.cs:67
System.Web.UI.Control.OnLoad(EventArgs e)
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Page.ProcessRequestMain()

This error is refering to the following Code Behind:

protected System.Web.UI.WebControls.DropDownList concat;
protected System.Web.UI.WebControls.DataGrid clubdg;
string strclubconn=ConfigurationSettings.AppSettings["ConnectionString"];
protected System.Web.UI.WebControls.HyperLink HyperLink1;
string userselect="SELECT User_tbl.*, ConCat.* FROM User_tbl, ConCat WHERE
User_tbl.concat=Concat.ContactID ORDER BY UserID Desc";
string strConCat="SELECT ConCat.* FROM ConCat";

public void BindData()
{
dsclub=new DataSet();
clubconn=new SqlConnection(strclubconn);
clubconn.Open();
clubadapt=new SqlDataAdapter(userselect,clubconn);
clubadapt.Fill(dsclub,"UserTbl");
clubadapt.SelectCommand=new SqlCommand(strConCat,clubconn);
clubadapt.Fill(dsclub,"ConCat");
clubconn.Close();

clubdg.DataSource=dsclub;
clubdg.DataMember=dsclub.Tables["UserTbl"].ToString();
clubdg.DataBind();

concat.DataSource=dsclub;
concat.DataMember=dsclub.Tables["ConCat"].ToString();
concat.DataTextField=dsclub.Tables["ConCat"].Columns["Catagory"].ToString();
concat.DataValueField=dsclub.Tables["ConCat"].Columns["ContactID"].ToString();
concat.DataBind();
}
This is the Front End DropDownList control: the error is refering to:

<asp:DropDownList ID="concat" Runat="server"></asp:DropDownList>

I don't know where the null referance is if any one can tell me what the
problem is I'd greatly appreciate it.

Sam I am-
 
M

Marina

'concat' is not an object. It is null.

Most likely the .aspx does not declare it correctly, so it is null on the
server.
 
K

Karl Seguin

Despite what you've shown us, contact must be null..even though you seem to
have it in the aspx page and seem to be declaring it protected in the
codebehind....maybe you are overwriting the value or something?

on a side note, instead of using:

concat.DataMember=dsclub.Tables["ConCat"].ToString();
concat.DataTextField=dsclub.Tables["ConCat"].Columns["Catagory"].ToString();
concat.DataValueField=dsclub.Tables["ConCat"].Columns["ContactID"].ToString(
);

why not just use:

concat.DataMember= "ConCat";
concat.DataTextField="Catagory";
concat.DataValueField="ContactID";

karl
--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
I am Sam said:
I keep getting the following exception error:

Object reference not set to an instance of an object.
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 215: clubdg.DataBind();
Line 216:
Line 217: concat.DataSource=dsclub;
Line 218: concat.DataMember=dsclub.Tables["ConCat"].ToString();
Line
219: concat.DataTextField=dsclub.Tables["ConCat"].Columns["Catagory"].ToString();


Source File: c:\inetpub\wwwroot\sonar3\secured\usergrid.aspx.cs Line: 217

Stack Trace:


[NullReferenceException: Object reference not set to an instance of an
object.]
Sonar3.Secured.UserGrid.BindData() in
c:\inetpub\wwwroot\sonar3\secured\usergrid.aspx.cs:217
Sonar3.Secured.UserGrid.Page_Load(Object sender, EventArgs e) in
c:\inetpub\wwwroot\sonar3\secured\usergrid.aspx.cs:67
System.Web.UI.Control.OnLoad(EventArgs e)
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Page.ProcessRequestMain()

This error is refering to the following Code Behind:

protected System.Web.UI.WebControls.DropDownList concat;
protected System.Web.UI.WebControls.DataGrid clubdg;
string strclubconn=ConfigurationSettings.AppSettings["ConnectionString"];
protected System.Web.UI.WebControls.HyperLink HyperLink1;
string userselect="SELECT User_tbl.*, ConCat.* FROM User_tbl, ConCat WHERE
User_tbl.concat=Concat.ContactID ORDER BY UserID Desc";
string strConCat="SELECT ConCat.* FROM ConCat";

public void BindData()
{
dsclub=new DataSet();
clubconn=new SqlConnection(strclubconn);
clubconn.Open();
clubadapt=new SqlDataAdapter(userselect,clubconn);
clubadapt.Fill(dsclub,"UserTbl");
clubadapt.SelectCommand=new SqlCommand(strConCat,clubconn);
clubadapt.Fill(dsclub,"ConCat");
clubconn.Close();

clubdg.DataSource=dsclub;
clubdg.DataMember=dsclub.Tables["UserTbl"].ToString();
clubdg.DataBind();

concat.DataSource=dsclub;
concat.DataMember=dsclub.Tables["ConCat"].ToString();
concat.DataTextField=dsclub.Tables["ConCat"].Columns["Catagory"].ToString();concat.DataValueField=dsclub.Tables["ConCat"].Columns["ContactID"].ToString(
);
concat.DataBind();
}
This is the Front End DropDownList control: the error is refering to:

<asp:DropDownList ID="concat" Runat="server"></asp:DropDownList>

I don't know where the null referance is if any one can tell me what the
problem is I'd greatly appreciate it.

Sam I am-
 

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

Top