Re: Problem with Object Reference?
From: Marina (someone_at_nospam.com)
Date: 07/27/04
- Next message: Paul: "simple style type question"
- Previous message: ASP.NET: "Re: FormsAuthentication.Encrypt and SSL"
- In reply to: Tim::..: "Problem with Object Reference?"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 27 Jul 2004 12:40:13 -0400
Is add_Office actually declared as a server side dropdown on your .aspx
page?
Basically, this kind of error happens when you declare the variable, but
don't instantiate it to an instance of an object. If the dropdown list with
the same id was on the .aspx page, asp.net would automatically match those
up and create the instance.
"Tim::.." <myatix_at_hotmail.com> wrote in message
news:2E11E00B-6C57-4618-9E9B-CE2F29111FC1@microsoft.com...
> Hi,
> I am trying to dynamically populate a dropdown list in a datagrid from a
database. However I keep getting the following error... WHY??? It seems to
be ok in the code but maybe I have to access it differently as it is in a
datagrid???
>
> dropdownlist id="add_office"
>
> Thanks for any help!
>
> ..::Error
> Object reference not set to an instance of an object.
>
> Source Error:
>
> Line 226: ' Get a new datareader from our command
> Line 227: Dim myReader As SqlDataReader = cmd.ExecuteReader()
> Line 228: add_Office.DataSource = myReader 'Error
> Line 229: add_Office.DataValueField = "officeID"
> Line 230: add_Office.DataTextField = "offName"
>
> ..:: CODE
>
> Sub PopulateDropdown()
> ' Only pull data from db on first page call.
> If Not Page.IsPostBack Then
>
>
> ' Create connection
> Dim Myconn As New
SqlConnection(ConfigurationSettings.AppSettings("strConn"))
> Dim cmd As New SqlCommand("SelectOffice", Myconn)
> cmd.CommandType = CommandType.StoredProcedure
>
> Myconn.Open()
>
> ' Get a new datareader from our command
> Dim myReader As SqlDataReader = cmd.ExecuteReader()
> add_Office.DataSource = myReader
> add_Office.DataValueField = "officeID"
> add_Office.DataTextField = "offName"
> add_Office.DataBind()
>
> myReader.Close()
>
> Myconn.Close()
> End If
> End Sub
- Next message: Paul: "simple style type question"
- Previous message: ASP.NET: "Re: FormsAuthentication.Encrypt and SSL"
- In reply to: Tim::..: "Problem with Object Reference?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|