Saturday, March 24, 2012

Object reference not set to an instance of an object

Hi,

I am pulling my hair out! I don't see why I am getting the error message.
There is data in the data reader. Notice that I have actually performed a
while/read on the data reader. Does anyone see why I am getting this error?

Thanks,

Andy

private void BindTypeDropDown()
{
SqlConnection oConn = new SqlConnection(DBConnectionString);
SqlCommand lCommand = new SqlCommand("sp_web_835_ddl_type",oConn);
lCommand.CommandType=CommandType.StoredProcedure;

oConn.Open();
SqlDataReader dtrTypeDDL = lCommand.ExecuteReader();

// while (dtrTypeDDL.Read())
// {
// Response.Write(dtrTypeDDL["code_value"] + " " + dtrTypeDDL
["short_description"] + "<br>");
// }

// Response.End();

ddlType.DataSource = dtrTypeDDL;
ddlType.DataValueField = "code_value";
ddlType.DataTextField = "short_description";
ddlType.DataBind();

dtrTypeDDL.Close();
oConn.Close();
}

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 87: //Response.End();
Line 88:
Line 89: ddlType.DataSource = dtrTypeDDL;
Line 90: ddlType.DataValueField = "code_value";
Line 91: ddlType.DataTextField = "short_description";

Source File: c:\inetpub\wwwroot\ecui_1\wpclaimansi835data.aspx. cs Line:
89

--
Message posted via http://www.dotnetmonster.comwhat is at line 89?

--
Regards,
Alvin Bruney - ASP.NET MVP

[Shameless Author Plug]
The Microsoft Office Web Components Black Book with .NET
Now available @. www.lulu.com/owc, Amazon.com etc
"Andy Sutorius via DotNetMonster.com" <forum@.nospam.DotNetMonster.com> wrote
in message news:bf54340bdcb446deb6d6670795170872@.DotNetMonste r.com...
> Hi,
> I am pulling my hair out! I don't see why I am getting the error message.
> There is data in the data reader. Notice that I have actually performed a
> while/read on the data reader. Does anyone see why I am getting this
> error?
> Thanks,
> Andy
> private void BindTypeDropDown()
> {
> SqlConnection oConn = new SqlConnection(DBConnectionString);
> SqlCommand lCommand = new SqlCommand("sp_web_835_ddl_type",oConn);
> lCommand.CommandType=CommandType.StoredProcedure;
> oConn.Open();
> SqlDataReader dtrTypeDDL = lCommand.ExecuteReader();
> // while (dtrTypeDDL.Read())
> // {
> // Response.Write(dtrTypeDDL["code_value"] + " " + dtrTypeDDL
> ["short_description"] + "<br>");
> // }
> // Response.End();
> ddlType.DataSource = dtrTypeDDL;
> ddlType.DataValueField = "code_value";
> ddlType.DataTextField = "short_description";
> ddlType.DataBind();
> dtrTypeDDL.Close();
> oConn.Close();
> }
>
> 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 87: // Response.End();
> Line 88:
> Line 89: ddlType.DataSource = dtrTypeDDL;
> Line 90: ddlType.DataValueField = "code_value";
> Line 91: ddlType.DataTextField = "short_description";
>
> Source File: c:\inetpub\wwwroot\ecui_1\wpclaimansi835data.aspx. cs Line:
> 89
> --
> Message posted via http://www.dotnetmonster.com

0 comments:

Post a Comment