Print Page | Close Window

New Collection() Error.

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: ASP.NET Discussion
Forum Description: Discussion and chat on ASP.NET related topics.
URL: https://forums.webwiz.net/forum_posts.asp?TID=11583
Printed Date: 29 March 2026 at 4:41am
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: New Collection() Error.
Posted By: davidshq
Subject: New Collection() Error.
Date Posted: 20 August 2004 at 2:55pm
Grrr...Just got redirected off this page and have to run to my other job, so everything I typed got wiped out. But basically, if anyone sees an error in this I'd appreciate your help, for some reason its finding Collection() as undefined.

Code:
Imports System
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls
Imports System.Data
Imports System.Data.OleDb

Public Class DataList
  Inherits Page

Private Sub Page_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  Dim colFruit As New Collection()
  colFruit.Add("Kiwi")
  colFruit.Add("Pear")
  colFruit.Add("Mango")
  colFruit.Add("Blueberry")
  colFruit.Add("Apricot")
  colFruit.Add("Banana")
  colFruit.Add("Peach")
  colFruit.Add("Plum")
  lstItems.DataSource=colFruit
  Me.DataBind()
  ' Could use lstItems.DataBind() to bind just the list box.
End Sub

End Class

Error:
Compiler Error Message:
BC30002: Type 'Collection' is not defined.

Source Error:


Line 11: 
Line 12: Private Sub Page_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Line 13: Dim colFruit As New Collection()
Line 14: colFruit.Add("Kiwi")
Line 15: colFruit.Add("Pear")


-------------
- http://www.davemackey.net/" rel="nofollow - Dave Mackey - Virtual Home.



Replies:
Posted By: Mart
Date Posted: 20 August 2004 at 3:10pm

Just put Imports System.Collections at the top with the other Imports statements



Posted By: Mart
Date Posted: 20 August 2004 at 4:02pm

But you don't need parenthesis, adding parenthesis makes it an array of collections, from the look of your code you only want 1 collection so it should be:

Dim colFruit As New Collection

 



Posted By: davidshq
Date Posted: 23 August 2004 at 1:25pm
Thanks for the advice...and I think that helped, but I am still receiving the same error.
David.


-------------
- http://www.davemackey.net/" rel="nofollow - Dave Mackey - Virtual Home.


Posted By: michael
Date Posted: 23 August 2004 at 4:42pm
The code is fine,  you must have the problem somewhere else, that it's throwing it there

-------------
http://baumannphoto.com" rel="nofollow - Blog | http://mpgtracker.com" rel="nofollow - MPG Tracker


Posted By: Mart
Date Posted: 23 August 2004 at 5:10pm

Try Importing these namespaces:

System.ComponentModel
System.ComponentModel.Design
System.ComponentModel.Design.Serialization



Posted By: davidshq
Date Posted: 24 August 2004 at 11:09am
Well, it ended up there were a number of errors in my code. Here is the code after repair for anyone who is interested. There were also two errors in the call for the code-behind. :-P Thanks for your help.
Imports System
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls
Imports System.Data
Imports System.Data.OleDb

Public Class Database
    Inherits Page
    Protected lstUser As ListBox ' Was not set previously.
Private Sub Page_Load (sender As Object, e as EventArgs) Handles MyBase.Load ' Was mistitled Private Class.
    ' Define a DataSet with a single DataTable.
    Dim dsInternal as New DataSet()
    dsInternal.Tables.Add("Users")

    ' Define two columns for this table.
    dsInternal.Tables("Users").Columns.Add("Name")
    dsInternal.Tables("Users").Columns.Add("Country")

    ' Add some actual information into the table.
    Dim rowNew as DataRow
    rowNew = dsInternal.Tables("Users").NewRow()
    rowNew("Name") = "John"
    rowNew("Country") = "Uganda"
    dsInternal.Tables("Users").Rows.Add(rowNew)

    rowNew = dsInternal.Tables("Users").NewRow()
    rowNew("Name") = "Samantha"
    rowNew("Country") = "Belgium"
    dsInternal.Tables("Users").Rows.Add(rowNew)

    rowNew = dsInternal.Tables("Users").NewRow()
    rowNew("Name") = "Rico"
    rowNew("Country") = "Japan"
    dsInternal.Tables("Users").Rows.Add(rowNew) ' Was missing closing ' quotation mark.

    ' Define the binding.
    lstUser.DataSource = dsInternal.Tables("Users")
    lstUser.DataTextField = "Name"

    Me.DataBind()
End Sub

End Class



-------------
- http://www.davemackey.net/" rel="nofollow - Dave Mackey - Virtual Home.



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net