473,408 Members | 2,441 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Error: No default member found for type MyClass

Dear Friends
I have a urgent problem to solve. I have created a class and its
collection and then bind it to a datagrid but got the following error.
Please help. Thanks in advance. Andy Eshtry

No default member found for type 'clsAgentPostalCode'

Line 44: Dim oAgentPostalCodeCollection As New

clsAgentPostalCodeCollection(lAgentID)
Line 45: dgPostalCode.DataSource = oAgentPostalCodeCollection
Line 46: dgPostalCode.DataBind()

----------------------------code in aspx
file ---------------------------------------
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

If Not Page.IsPostBack Then

dgPostalCode.DataKeyField = "AssignedPostalCodeID"
'dgPostalCode.DataSource = GetPostalCodeList()
Dim oAgentPostalCodeCollection As New
clsAgentPostalCodeCollection(lAgentID)
dgPostalCode.DataSource = oAgentPostalCodeCollection
dgPostalCode.DataBind()

End If
End Sub
--------------------clsAgentPostalCode -------------------------------------
------

Public Class clsAgentPostalCode
Public mAgentPostalCodeID As Long
Public mAssignedPostalCodeID As Long
Public mAgentID As Long
Public mAssignedPostalCode As String
Private mSelected As Boolean
Private mPrevSelected As Boolean

Public ReadOnly Property AgentPostalCodeID() As Long
Get
Return mAgentPostalCodeID
End Get
End Property

Public ReadOnly Property AgentID() As Long
Get
Return mAgentID
End Get
End Property

Public ReadOnly Property AssignedPostalCode() As String
Get
Return mAssignedPostalCode
End Get
End Property
Public ReadOnly Property AssignedPostalCodeID() As Long
Get
Return mAssignedPostalCodeID
End Get
End Property

Public Sub New(ByVal parAssignedPostalCodeID As Long, ByVal parSelected
As Boolean, _
ByVal parAssignedPostalCode As String, ByVal parAgentPostalCodeID As
Long, ByVal parAgentID

As Long)
mAgentPostalCodeID = parAgentPostalCodeID
mAssignedPostalCodeID = parAssignedPostalCodeID

mAgentID = parAgentID
mSelected = parSelected
mPrevSelected = parSelected
mAssignedPostalCode = parAssignedPostalCode
End Sub

Public Property Selected() As Boolean
Get
Return Selected
End Get
Set(ByVal Value As Boolean)
Selected = Value
End Set
End Property
End Sub
End Class

---------------------clsAgentPostalCodeCollection-----------------------

Imports System.Collections
Public Class clsAgentPostalCodeCollection
Inherits CollectionBase

Public Sub New(ByVal parAgentID As Long)
Dim sConStr As String
Dim oConfSetting As ConfigurationSettings
sConStr = oConfSetting.AppSettings("ConStr").ToString()
Dim Cn As SqlConnection
Dim daPostalCode As SqlDataAdapter
Dim dsPostalCode As New DataSet()
Try
Cn = New SqlConnection(sConStr)

Dim cmdSel As SqlCommand = New
SqlCommand("spAgentAssignedPostalCode", Cn)
cmdSel.CommandType = CommandType.StoredProcedure
cmdSel.Parameters.Add(New SqlParameter("@AgentID", parAgentID))
Cn.Open()
daPostalCode = New SqlDataAdapter(cmdSel)
daPostalCode.Fill(dsPostalCode, "tblPostalCode")
Cn.Close()

Dim AgentPostalCodeRow As DataRow
For Each AgentPostalCodeRow In
dsPostalCode.Tables("tblPostalCode").Rows
Dim par1 As Long =
AgentPostalCodeRow.Item("AssignedPostalCodeID")
Dim par2 As Boolean = AgentPostalCodeRow.Item("Selected")
Dim par3 As String =
AgentPostalCodeRow.Item("AssignedPostalCode")
Dim par4 As Long
If Not
IsDBNull(AgentPostalCodeRow.Item("AgentPostalCodeI D")) Then
par4 = AgentPostalCodeRow.Item("AgentPostalCodeID")
Else
par4 = 0
End If
Dim par5 As Long

If Not IsDBNull(AgentPostalCodeRow.Item("ID_Agent")) Then
par5 = AgentPostalCodeRow.Item("ID_Agent")
Else
par5 = 0
End If

Dim AgentPostalCodeItem As New clsAgentPostalCode(par1,
par2, par3, par4, par5)
Add(AgentPostalCodeItem)
Next
Catch ex As Exception
Throw ex
End Try

End Sub

Public Sub Add(ByVal AgentPostalCodeItem As clsAgentPostalCode)

List.Add(AgentPostalCodeItem)
End Sub

Public Sub Remove(ByVal index As Integer)

If (index > Count - 1 Or index < 0) Then

Else
List.RemoveAt(index)

End If
End Sub

Public Function Item(ByVal Index As Integer) As clsAgentPostalCode

Return CType(List(Index), clsAgentPostalCode)
End Function

Public ReadOnly Property Length() As Long
Get
Return List.Count
End Get
End Property

Public Function Find(ByVal id As Long) As clsAgentPostalCode
Dim AgentPostalCodeItem As clsAgentPostalCode

For Each AgentPostalCodeItem In InnerList
If AgentPostalCodeItem.AgentPostalCodeID = id Then
Return AgentPostalCodeItem
End If
Next
Return Nothing
End Function

End Class

Nov 15 '05 #1
3 1733
Cor
Hi Andy,

You try to make from your dataset a collection to bind that to a datagrid.
The ideal collection to bind to a datagrid as a datasource is the datatable
a part of the dataset.

What is the reason you take this very difficult route?
(While it is a webpage and therefore the collection is gone when you have
binded it, because I do not see it been saved somewhere by you).

Cor
Nov 15 '05 #2
Thank you very much. Is there a sample code I can use to bind a user defined
collection to a
datagrid.
I used collection cause I want to assigned mulitple postal code to agents so
it is a many to many relationship and I have used "prevselected" and
"selected" properties to track which checkboxes of each postal code the user
checked or unchecked in a grid so that only add or delete a row in the
middle table (between postal code and agent tables) and do nothing for the
postal code that there were no activity on them by user.
Default Public ReadOnly Property Item(ByVal Index As Integer) As
clsAgentPostalCode

Get

Return CType(List(Index), clsAgentPostalCode)

End Get

End Property

Would you please what is wrong to my databinding code?

If Not Page.IsPostBack Then

dgPostalCode.DataKeyField = "AssignedPostalCodeID"

Dim oAgentPostalCodeCollection As New clsAgentPostalCodeCollection(lAgentID)

dgPostalCode.DataSource = oAgentPostalCodeCollection

dgPostalCode.DataBind()

End If

"Cor" <no*@non.com> wrote in message
news:eV**************@TK2MSFTNGP09.phx.gbl...
Hi Andy,

You try to make from your dataset a collection to bind that to a datagrid.
The ideal collection to bind to a datagrid as a datasource is the datatable a part of the dataset.

What is the reason you take this very difficult route?
(While it is a webpage and therefore the collection is gone when you have
binded it, because I do not see it been saved somewhere by you).

Cor

Nov 15 '05 #3
Cor
Hi Andy,

I would start with trying
dgPostalCode.DataSource =dsPostalCode.tables("tblPostalCode)

Give it a try?

Cor
Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: AIM | last post by:
Error in msvc in building inheritance.obj to build hello.pyd Hello, I am trying to build the boost 1.31.0 sample extension hello.cpp. I can not compile the file inheritance.cpp because the two...
0
by: Andy Eshtry | last post by:
Dear Friends I have a urgent problem to solve. I have created a class and its collection and then bind it to a datagrid but got the following error. Please help. Thanks in advance. Andy Eshtry ...
4
by: Serge | last post by:
Hi, I have no problem creating a static member variable with integers, etc but when I try the same with a vector then I always get linker errors that the static member variable is unknown...
5
by: Enos Meroka | last post by:
Hallo, I am a student doing my project in the university.. I have been trying to compile the program using HP -UX aCC compiler, however I keep on getting the following errors. ...
6
by: Peter Frost | last post by:
Please help I don't know if this is possible but what I would really like to do is to use On Error Goto to capture the code that is being executed when an error occurs. Any help would be much...
2
by: Christoph Boget | last post by:
Let's take the following class: class MyClass { private int privateVar; public int PublicVar { get { return privateVar; } } public MyClass() {}
0
by: HKSHK | last post by:
This list compares the error codes used in VB.NET 2003 with those used in VB6. Error Codes: ============ 3: This Error number is obsolete and no longer used. (Formerly: Return without GoSub)...
12
by: WaterWalk | last post by:
Hello. I am rather confused by the type of a pointer to class data member. Many c++ texts say that pointer to data member has a special syntax. For example the following class: class MyClass {...
14
by: Neviton | last post by:
Help with this error ! Please ! The code below is simplified, because I'm trying to solve this error. ....MyClass.cpp In member function `void MyClass::Initialize()': ....MyClass.cpp aggregate...
10
by: happyse27 | last post by:
Hi All, I got this apache errors(see section A1 and A2 below) when I used a html(see section b below) to activate acctman.pl(see section c below). Section D below is part of the configuration...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.