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