Problem populating ddl from Oracle

P

Problematic coder

Here is the main code:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
buildYearDDLs(FindControl("ddlSample"))
End sub

Private Sub buildYearDDLs(ByVal c As Control)
Dim objdr As Data.OracleClient.OracleDataReader = Nothing
Dim objcnn As Data.OracleClient.OracleConnection = Nothing
Dim objcom As Data.OracleClient.OracleCommand = Nothing
Dim strErrorMsg As String = ""
Dim DDLAddYear As DropDownList = Nothing
Dim liBlank As ListItem = Nothing
Try
objcnn = New
Data.OracleClient.OracleConnection(utilities.getConnectionString)
objcnn.Open()
objcom = New
Data.OracleClient.OracleCommand(utilities.BuildSQL("populateYear",
"None"), objcnn)
objdr = objcom.ExecuteReader()
Try
DDLAddYear = CType(c, DropDownList)
With DDLAddYear
.DataSource = objdr ' This is where I get the
error described below
.DataTextField = "DDL_YEAR"
.DataValueField = "DDL_YEAR"
.DataBind()
End With
liBlank = New ListItem("", "")
DDLAddYear.Items.Insert(0, liBlank)
Catch ex As Exception
'Deal with error
Finally
objdr.Close()
End Try
Catch ex As Exception
'Deal with error
Finally
End Try
End Sub

The error is:

System.NullReferenceException: Object reference not set to an instance
of an object. at interest_form.buildYearDDLs(Control c) in C:
\Documents and Settings\uid\My Documents\Visual Studio 2005\WebSites
\WebSite5\page.aspx.vb:line ....

I have no idea why I am getting this, I would appreciate any
assistance

Thanks
 
P

Problematic Coder

I resolved the problem, I was reusing code from a ddl within a datagrid and
that was making it more comples that needed:

buildYearDDLs(FindControl("ddlSample"))
to
buildYearDDLs(ddlSample)
&
DDLAddYear = CType(c, DropDownList)
to
DDLAddYear = c

Seemed to do the job just fine, I wanted to be able to pass the ddl since I
want to re-use the code for other ddls

Hope this helps someone in future
 

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