473,396 Members | 1,671 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,396 software developers and data experts.

RE: No parameterless constructor error for dataview

Solved it. I had to rewrite my classes in my business & datalayer changing
their constructors.

Julia

"Julia B" wrote:
Apologies for the cross posting. I posted to the datagrid group a couple of
weeks ago, but haven't got an answer so am trying here.

I've got a 3 tiered application in .net 2.0 and am using dataviews for the
first time.

(tier 1) web layer with forms - RC_Web_AccountMonitor
(tier 2) business logic - RC_BL_AccountMonitor
(tier 3) data connection - RC_DL_AccountMonitor

I'm trying to load some data into a dataview, with a datasource that is an
ObjectDataSource object and getting the message "No parameterless constructor
defined for this object". Basically the webform is in tier 1, which calls a
function called DisplayUsers in tier 2 (within the Users class), which in
turn calls a couple of functions/subs in tier 3. This is how it's set up.

The ObjectDataSource object has
a TypeName of RC.RC_BL_AccountMonitor.User
a SelectMethod of DisplayUsers
and a Parameter Name of userCurrent with value of 1
Class BL_User looks like this:

Namespace RC_BL_AccountMonitor

Public Class User
'This class is used for displaying & updating user records.
'It is not used for getting the current user's rights which is done
'in the BL_AppAdmin class
#Region "Fields"
'These field names map to the fields within the Users table except the
'fields don't have a _ prefix
Private _userID As Integer
Private _forename As String
Private _surname As String
Private _middleInitial As String
Private _roleID As Integer
Private _networkID As String
Private _emailAddress As String
Private _deptID As Integer
Private _startDate As Date
Private _leaveDate As Date
Private _temp As Boolean
Private _hrReceivedEmails As Boolean
Private _facilitiesReceivedEmails As Boolean
Private _userCurrent As Boolean

#End Region

#Region "Properties"
Public Property UserID() As Integer
Get
Return _userID
End Get
Set(ByVal value As Integer)
_userID = value
End Set
End Property

Public Property Forename() As String
Get
Return _forename
End Get
Set(ByVal value As String)
_forename = value
End Set
End Property

Public Property Surname() As String
Get
Return _surname
End Get
Set(ByVal value As String)
_surname = value
End Set
End Property

Public Property MiddleInitial() As String
Get
Return _middleInitial
End Get
Set(ByVal value As String)
_middleInitial = value
End Set
End Property

Public Property RoleID() As Integer
Get
Return _roleID
End Get
Set(ByVal value As Integer)
_roleID = value
End Set
End Property

Public Property NetworkID() As String
Get
Return _networkID
End Get
Set(ByVal value As String)
_networkID = value
End Set
End Property

Public Property EmailAddress() As String
Get
Return _emailAddress
End Get
Set(ByVal value As String)
_emailAddress = value
End Set
End Property

Public Property DeptID() As Integer
Get
Return _deptID
End Get
Set(ByVal value As Integer)
_deptID = value
End Set
End Property

Public Property StartDate() As Date
Get
Return _startDate
End Get
Set(ByVal value As Date)
_startDate = value
End Set
End Property

Public Property LeaveDate() As Date
Get
Return _leaveDate
End Get
Set(ByVal value As Date)
_leaveDate = value
End Set
End Property

Public Property Temp() As Boolean
Get
Return _temp
End Get
Set(ByVal value As Boolean)
_temp = value
End Set
End Property

Public Property HRReceivedEmails() As Boolean
Get
Return _hrReceivedEmails
End Get
Set(ByVal value As Boolean)
_hrReceivedEmails = value
End Set
End Property

Public Property FacilitiesReceivedEmails() As Boolean
Get
Return _facilitiesReceivedEmails
End Get
Set(ByVal value As Boolean)
_facilitiesReceivedEmails = value
End Set
End Property

Public Property UserCurrent() As Boolean
Get
Return _userCurrent
End Get
Set(ByVal value As Boolean)
_userCurrent = value
End Set
End Property

#End Region

#Region "Constructors"
Public Sub New(ByVal UserID As Integer, ByVal Forename As String, _
ByVal Surname As String, ByVal MiddleInitial As
String, _
ByVal RoleID As Integer, ByVal NetworkID As String, _
ByVal EmailAddress As String, ByVal DeptID As
Integer, _
ByVal StartDate As Date, ByVal LeaveDate As Date, _
ByVal Temp As Boolean, ByVal HRReceivedEmails As
Boolean, _
ByVal FacilitiesReceivedEmails As Boolean, _
ByVal UserCurrent As Boolean)

_userID = UserID
_forename = Forename
_surname = Surname
_middleInitial = MiddleInitial
_roleID = RoleID
_networkID = NetworkID
_emailAddress = EmailAddress
_deptID = DeptID
_startDate = StartDate
_leaveDate = LeaveDate
_temp = Temp
_hrReceivedEmails = HRReceivedEmails
_facilitiesReceivedEmails = FacilitiesReceivedEmails
_userCurrent = UserCurrent
End Sub

#End Region

#Region "OtherVariables"
Private _ConnectionStr As String = ""
#End Region

Public Sub New(ByVal ConnectionStr As String)
_ConnectionStr = ConnectionStr
End Sub

Public Function DisplayUsers(ByVal userCurrent As Integer) As DataSet
'This function returns a dataset which displays a list of users
'it uses the dl level getdatasetfromsp function

Dim dsDataGrid As DataSet

With New RC.RC_DL_AccountMonitor.DL_Connection(_ConnectionS tr)
.AddParameter("@userCurrent", SqlDbType.Int, 0, userCurrent)
dsDataGrid = .GetDatasetFromSP("sp_AllCurrentUsers")
End With

Return dsDataGrid

End Function

End Class

End Namespace

The db level DL_Connection class looks like this:
Imports System.Data.SqlClient

Namespace RC_DL_AccountMonitor

Public Class DL_Connection

Private _ParamList As SqlParameterCollection
Private _MyComm As New SqlCommand

Private _ConnectionStr As String = ""
Public Sub New(ByVal ConnectionStr As String)
_ConnectionStr = ConnectionStr
End Sub

Public Function GetDatasetFromSP(ByVal SPName As String) As DataSet
Dim Myds As New DataSet
Dim ConnectionStr As String = _ConnectionStr
Dim Myconn As New SqlConnection(ConnectionStr)
Dim MyAdapter As New SqlDataAdapter(_MyComm)
_MyComm.CommandType = CommandType.StoredProcedure
_MyComm.CommandText = SPName

Myconn.Open()
Try
_MyComm.Connection = Myconn
MyAdapter.Fill(Myds, "Results")
Catch ex As Exception
'#### need to add something here
Finally
Myconn.Close()
End Try

Return Myds

End Function

Public Sub AddParameter(ByVal ParamName As String, ByVal paramType
As Data.SqlDbType, ByVal Paramlenght As Int16, ByVal ParamValue As String)
_MyComm.Parameters.Add(ParamName, paramType, Paramlenght)
_MyComm.Parameters(ParamName).Value = ParamValue
End Sub

End Class

End Namespace

Stored procedure sp_AllCurrentUsers is written like this (and works):

ALTER PROCEDURE sp_AllCurrentUsers
/*
Name: sp_AllCurrentUsers
Description: Used to display all current users for IT personnel for user
management
*/

(
@userCurrent int
)
AS
SELECT Surname, MiddleInitial, Forename, Role, NetworkID, EmailAddress,
Oct 2 '08 #1
3 1571
Julia would you mind sharing the key points of your fix? I'm running into the
same problem here. I have a default constructor in my data entity, the BL is
all Shared subs - no instantiation, the data access has a default
constructor. I tried adding some data and a constructor to the BL class, but
it didn't help. What did you do to your c'tor to make it work?

TIA
Mike

"Julia B" wrote:
Solved it. I had to rewrite my classes in my business & datalayer changing
their constructors.

Julia

"Julia B" wrote:
Apologies for the cross posting. I posted to the datagrid group a couple of
weeks ago, but haven't got an answer so am trying here.
.... SNIP
Oct 25 '08 #2
Mike, apologies for the long delay in responding, I didn't read your post
till today. Anyway, if I can still help here's what I did (with a simpler
example than when I originally posted):

Tier 1 - web layer
My object datasource properties are:

TypeName RC.RC_Web_AccountMonitor.CommonUtilities
SelectMethod FillDataGrid
Select Parameters Name spName Value sp_DepartmentList

Tier 2 - business layer

Imports System.Data.SqlClient

Namespace RC_Web_AccountMonitor

Public Class CommonUtilities
Public Sub New()

End Sub

Public Function FillDataGrid(ByVal spName As String) As DataSet
Dim dsDataGrid As DataSet

'this function returns a dataset that fills an unparametered
datagrid
With New DBConnection
dsDataGrid = .GetDatasetFromSP(spName)
End With
Return dsDataGrid

End Function

End Class

End Namespace

Tier 3 - data layer

Imports System.Data.SqlClient

Public Class DBConnection

Private _ParamList As SqlParameterCollection
Private _MyComm As New SqlCommand

Private _ConnectionStr As String =
ConfigurationManager.ConnectionStrings("Conn").ToS tring

'shared connection
Dim conn As New SqlConnection(_ConnectionStr)

Public Sub New()

End Sub

Public Function GetDatasetFromSP(ByVal SPName As String) As DataSet

Dim Myds As New DataSet

Dim MyAdapter As New SqlDataAdapter(_MyComm)
_MyComm.CommandType = CommandType.StoredProcedure
_MyComm.CommandText = SPName

_MyComm.Connection = conn
Try
MyAdapter.Fill(Myds, "Results")
Catch ex As Exception
System.Web.HttpContext.Current.Session("DBError") = "True"
System.Web.HttpContext.Current.Session("DBEx") = ex.ToString
Finally

End Try
Return Myds

End Function

End Class

End Namespace

This works fine. I hope this helps.
Julia

"Mike Baker" wrote:
Julia would you mind sharing the key points of your fix? I'm running into the
same problem here. I have a default constructor in my data entity, the BL is
all Shared subs - no instantiation, the data access has a default
constructor. I tried adding some data and a constructor to the BL class, but
it didn't help. What did you do to your c'tor to make it work?

TIA
Mike

"Julia B" wrote:
Solved it. I had to rewrite my classes in my business & datalayer changing
their constructors.

Julia

"Julia B" wrote:
Apologies for the cross posting. I posted to the datagrid group a couple of
weeks ago, but haven't got an answer so am trying here.
>
.... SNIP
Nov 6 '08 #3
Hi Julia,

Thanks for taking the time to get back to me. I found a different solution
to mine. If I remember correctly the reason for my error message was that I
was passing the object by reference in one of the data access methods by
mistake.

Mike
"Julia B" wrote:
Mike, apologies for the long delay in responding, I didn't read your post
till today. Anyway, if I can still help here's what I did (with a simpler
example than when I originally posted):

Tier 1 - web layer
My object datasource properties are:

TypeName RC.RC_Web_AccountMonitor.CommonUtilities
SelectMethod FillDataGrid
Select Parameters Name spName Value sp_DepartmentList

Tier 2 - business layer

Imports System.Data.SqlClient

Namespace RC_Web_AccountMonitor

Public Class CommonUtilities
Public Sub New()

End Sub

Public Function FillDataGrid(ByVal spName As String) As DataSet
Dim dsDataGrid As DataSet

'this function returns a dataset that fills an unparametered
datagrid
With New DBConnection
dsDataGrid = .GetDatasetFromSP(spName)
End With
Return dsDataGrid

End Function

End Class

End Namespace

Tier 3 - data layer

Imports System.Data.SqlClient

Public Class DBConnection

Private _ParamList As SqlParameterCollection
Private _MyComm As New SqlCommand

Private _ConnectionStr As String =
ConfigurationManager.ConnectionStrings("Conn").ToS tring

'shared connection
Dim conn As New SqlConnection(_ConnectionStr)

Public Sub New()

End Sub

Public Function GetDatasetFromSP(ByVal SPName As String) As DataSet

Dim Myds As New DataSet

Dim MyAdapter As New SqlDataAdapter(_MyComm)
_MyComm.CommandType = CommandType.StoredProcedure
_MyComm.CommandText = SPName

_MyComm.Connection = conn
Try
MyAdapter.Fill(Myds, "Results")
Catch ex As Exception
System.Web.HttpContext.Current.Session("DBError") = "True"
System.Web.HttpContext.Current.Session("DBEx") = ex.ToString
Finally

End Try
Return Myds

End Function

End Class

End Namespace

This works fine. I hope this helps.
Julia

"Mike Baker" wrote:
Julia would you mind sharing the key points of your fix? I'm running into the
same problem here. I have a default constructor in my data entity, the BL is
all Shared subs - no instantiation, the data access has a default
constructor. I tried adding some data and a constructor to the BL class, but
it didn't help. What did you do to your c'tor to make it work?

TIA
Mike

"Julia B" wrote:
Solved it. I had to rewrite my classes in my business & datalayer changing
their constructors.
>
Julia
>
"Julia B" wrote:
>
Apologies for the cross posting. I posted to the datagrid group a couple of
weeks ago, but haven't got an answer so am trying here.

>.... SNIP
Nov 21 '08 #4

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

Similar topics

3
by: brian c | last post by:
************************************** //Load the Assembly Assembly a = Assembly.LoadFrom(sAssembly); //Get Types so we can Identify the Interface. Type mytypes = a.GetTypes(); BindingFlags...
4
by: Robert Zurer | last post by:
Hello All, Is it considered a best practice to always write a parameterless constructor for any object - just in case? I'm not sure. I want my object to have all it absolutely requires to...
12
by: Ole Nielsby | last post by:
Why is this? I've stumbled on this restriction more than once, and I'd like to know the philosophy behind it if there is one. I figure I'd be less prone to make this error if I knew the reason....
0
by: JymBoe | last post by:
I have built a Web Service with a multi-table dataset. When I attempt to discover the Web Service, I get an error saying "ItemsRow has no parameterless constructor" where ItemsRow is a row in the...
1
by: Nathan Sokalski | last post by:
I have created a custom control for ASP.NET using VB.NET. My control inherits from the System.Web.UI.WebControls.CompositeControl class, and is working fine. However, the Visual Studio .NET designer...
3
by: dippykdog | last post by:
Does anyone know why there isn't a parameterless constructor for the String type? Given that you can... Dim s as New String("Hello") ' inefficient, don't do this I guess I would have...
2
by: Hans Kesting | last post by:
on 23-9-2008, Julia B supposed : Usually that errormessage means that you derived a class from a baseclass that has no parameterless constructors. Always when you call a constructor, a...
2
by: bednarz.thomas | last post by:
I have the following business Object(s): public class ParentObject { public ParentObject(string somestring) { ...- } ....
9
by: puzzlecracker | last post by:
"The C# specification states that all value types have a default parameterless constructor, and it uses the same syntax to call both explicitly declared constructors and the parameterless one,...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...

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.