G
Guest
Hi All,
I have a code below:-
That Binds a DropDownList to a database using ArrayList.
This code works well in ASP.NET webMatrix.
But when i use it below in VS.NEt it gives me the error:-
System.NullReferenceException: Object reference not set to an instance of an
object.
Can amybody tell me what 'm doing wrong in VS.NET i have been having problem
with this ArrayList when using it with VS.NET
Thanks
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Dim MyArrayList As ArrayList
Dim sItem As String
MyArrayList = New ArrayList
If Not Page.IsPostBack Then
Dim strConn As String =
"server=(local);database=Northwind;integrated security=true;"
Dim MySQL As String = "Select CategoryName from Categories"
Dim MyConn As New SQLConnection(strConn)
Dim objDR As SQLDataReader
Dim Cmd As New SQLCommand(MySQL, MyConn)
MyConn.Open()
objDR =
Cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection)
While objDR.Read()
MyArrayList.add(objDR("CategoryName"))
End While
End If
ddl1.DataSource = MyArrayList
ddl1.databind()
End Sub
I have a code below:-
That Binds a DropDownList to a database using ArrayList.
This code works well in ASP.NET webMatrix.
But when i use it below in VS.NEt it gives me the error:-
System.NullReferenceException: Object reference not set to an instance of an
object.
Can amybody tell me what 'm doing wrong in VS.NET i have been having problem
with this ArrayList when using it with VS.NET
Thanks
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Dim MyArrayList As ArrayList
Dim sItem As String
MyArrayList = New ArrayList
If Not Page.IsPostBack Then
Dim strConn As String =
"server=(local);database=Northwind;integrated security=true;"
Dim MySQL As String = "Select CategoryName from Categories"
Dim MyConn As New SQLConnection(strConn)
Dim objDR As SQLDataReader
Dim Cmd As New SQLCommand(MySQL, MyConn)
MyConn.Open()
objDR =
Cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection)
While objDR.Read()
MyArrayList.add(objDR("CategoryName"))
End While
End If
ddl1.DataSource = MyArrayList
ddl1.databind()
End Sub