Click here to Skip to main content
15,889,034 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
VB
Public Class CommonDropDownList
        Inherits System.Web.UI.Page
        Sub New()
        End Sub
        Sub FillDropDownList(ByVal myDropDown As DropDownList, ByVal SqlString As String, ByVal txtName As String, ByVal valueName As String, ByVal extraRow As String, ByVal extraRowVal As String)
                      ConnectDB()
            Conn.Open()
            Dim myCommand As New OleDbCommand(SqlString, Conn)
                       myDropDown.DataSource = myCommand.ExecuteReader()
            myDropDown.DataTextField = txtName
            myDropDown.DataValueField = valueName

            myDropDown.DataBind()
            Conn.Close()
            If Not extraRow = "" Then
                myDropDown.Items.Insert(0, New ListItem(extraRow, extraRowVal))
                myDropDown.SelectedIndex = 0
            End If
        End Sub


This is a common code and I am using the following code in the page load 

If Not IsPostBack Then


            sqlstr = "select lpad(level,2,'0')mth from dual connect by level<13"
            BindDDL.FillDropDownList(ddlMth, sqlstr, "mth", "mth", "Select", "Select")
            sqlstr = "select (to_char(sysdate,'yyyy')-level+1)yr from dual connect by level<6"
            BindDDL.FillDropDownList(ddlYear, sqlstr, "yr", "yr", "Select", "Select")


        End If

I am getting the Null Exception on running the code though the individual queries are running perfectly fine...How can I correct it please help
Posted
Updated 19-Nov-12 17:34pm
v2
Comments
Pro Idiot 19-Nov-12 23:34pm    
On which line , you are getting the null exception ?
beg_coder 21-Nov-12 5:04am    
BindDDL.FillDropDownList(ddlMth, sqlstr, "mth", "mth", "Select", "Select")
Pro Idiot 19-Nov-12 23:35pm    
May be you have not initialized the BindDDL object
beg_coder 21-Nov-12 5:06am    
Oh..yes..thanks a lot i have coded it like a mess and hence silly mistakes...thanx a lot @Pro Idiot and @Sanjay K. Gupta for your time and help
Sanjay K. Gupta 19-Nov-12 23:38pm    
1. Are you using SQL Server? if not then please mention the Database
2. In which line you are getting NULL Exception?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900