I am having huge problems with a null referance

G

Guest

The codebehind is as follows:
I have instenced the DataSet dsclub2a
protected System.Data.DataSet dsclub2a;
and I have instanced the DropdownList as follows:
protected System.Web.UI.WebControls.DropDownList ConCat1;

public void ContactCat()
{
dsclub2a=new DataSet();
clubconn=new SqlConnection(strclubconn);
clubadapt2=new SqlDataAdapter(strConCat,clubconn);
clubadapt2.Fill(dsclub2a,"ConCatagory");

ConCat1.DataSource=dsclub2a;
ConCat1.DataMember="ConCatagory";
ConCat1.DataTextField="Catagory";
ConCat1.DataValueField="ContactID";
ConCat1.DataBind();
}
In the Interface HTML file I have typed the following:

<asp:DropDownList id="ConCat1" runat="server"></asp:DropDownList>

I keep getting the following 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 219: clubadapt2.Fill(dsclub2a,"ConCatagory");
Line 220:
Line 221: ConCat1.DataSource=dsclub2a;
Line 222: ConCat1.DataMember="ConCatagory";
Line 223: ConCat1.DataTextField="Catagory";


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

Stack Trace:


[NullReferenceException: Object reference not set to an instance of an
object.]
Sonar3.Secured.UserGrid.ContactCat() in
c:\inetpub\wwwroot\sonar3\secured\usergrid.aspx.cs:221
Sonar3.Secured.UserGrid.Edit_Click(Object sender,
DataGridCommandEventArgs e) in
c:\inetpub\wwwroot\sonar3\secured\usergrid.aspx.cs:72
System.Web.UI.WebControls.DataGrid.OnEditCommand(DataGridCommandEventArgs
e)
System.Web.UI.WebControls.DataGrid.OnBubbleEvent(Object source, EventArgs
e)
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
System.Web.UI.WebControls.DataGridItem.OnBubbleEvent(Object source,
EventArgs e)
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e)

System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
System.Web.UI.Page.ProcessRequestMain()


Both ConCat1 and dsclub2a have been referanced properly. I do not know what
object the error message is refering to. I have used other names for these
objects as well and it still returns the same error. Is there something I am
missing?

I'm in real big trouble here I need to fix this. If someone can help me
figure it out I'll be truly greatful.

Sam-
 
P

Patrick Olurotimi Ige

Sam ur code looks ok..
Hope i looked through it well!!!

What namespaces did u import?
Did you import
using System.Data;
 
P

Patrick Olurotimi Ige

But Sam after looking through it again in ur dropdownlist
<asp:DropDownList id="ConCat1" runat="server"></asp:DropDownList>
U are not retrieving any values for example like below

<asp:DropDownList id="ConCat1"
runat="server"
DataTextField="Catagory"
DataValueField="ContactID"
AutoPostBack="true" />


Let me know if that helps
Patrick
 
G

Guest

No that doesn't correct the problem. I am thinking I should call the
datasource in the actual DropDownList itself using <asp:DropDownList
ID="ConCat1a" DataSource="dsclub" DataMember="ConCat" Runat="server"
DataTextField="ContactID" DataValueField="Catagory" />

What do you think? Will that work?
 
G

Guest

It did the trick perfectly.

I just referanced the DataTable in the DropDownList control as such:

<asp:DropDownList ID="whatever_The_ID_IS" Datasource="<%# DataSet_Name%>"
DataMember="Table_Name" DataTextField="Column" DataValueField="PK_Column"
Runat="server"/>

that worked great. You have to keep in mind the Binding tags encapsolating
the DataSet Name. Very Important otherwise it won't bind to the DropDownList
control.

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

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top