473,698 Members | 1,888 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_AccountM onitor
(tier 2) business logic - RC_BL_AccountMo nitor
(tier 3) data connection - RC_DL_AccountMo nitor

I'm trying to load some data into a dataview, with a datasource that is an
ObjectDataSourc e 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 ObjectDataSourc e object has
a TypeName of RC.RC_BL_Accoun tMonitor.User
a SelectMethod of DisplayUsers
and a Parameter Name of userCurrent with value of 1
Class BL_User looks like this:

Namespace RC_BL_AccountMo nitor

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 _hrReceivedEmai ls As Boolean
Private _facilitiesRece ivedEmails 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 HRReceivedEmail s() As Boolean
Get
Return _hrReceivedEmai ls
End Get
Set(ByVal value As Boolean)
_hrReceivedEmai ls = value
End Set
End Property

Public Property FacilitiesRecei vedEmails() As Boolean
Get
Return _facilitiesRece ivedEmails
End Get
Set(ByVal value As Boolean)
_facilitiesRece ivedEmails = 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 "Constructo rs"
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 HRReceivedEmail s As
Boolean, _
ByVal FacilitiesRecei vedEmails 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
_hrReceivedEmai ls = HRReceivedEmail s
_facilitiesRece ivedEmails = FacilitiesRecei vedEmails
_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(By Val userCurrent As Integer) As DataSet
'This function returns a dataset which displays a list of users
'it uses the dl level getdatasetfroms p function

Dim dsDataGrid As DataSet

With New RC.RC_DL_Accoun tMonitor.DL_Con nection(_Connec tionStr)
.AddParameter(" @userCurrent", SqlDbType.Int, 0, userCurrent)
dsDataGrid = .GetDatasetFrom SP("sp_AllCurre ntUsers")
End With

Return dsDataGrid

End Function

End Class

End Namespace

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

Namespace RC_DL_AccountMo nitor

Public Class DL_Connection

Private _ParamList As SqlParameterCol lection
Private _MyComm As New SqlCommand

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

Public Function GetDatasetFromS P(ByVal SPName As String) As DataSet
Dim Myds As New DataSet
Dim ConnectionStr As String = _ConnectionStr
Dim Myconn As New SqlConnection(C onnectionStr)
Dim MyAdapter As New SqlDataAdapter( _MyComm)
_MyComm.Command Type = CommandType.Sto redProcedure
_MyComm.Command Text = SPName

Myconn.Open()
Try
_MyComm.Connect ion = 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(By Val ParamName As String, ByVal paramType
As Data.SqlDbType, ByVal Paramlenght As Int16, ByVal ParamValue As String)
_MyComm.Paramet ers.Add(ParamNa me, paramType, Paramlenght)
_MyComm.Paramet ers(ParamName). Value = ParamValue
End Sub

End Class

End Namespace

Stored procedure sp_AllCurrentUs ers is written like this (and works):

ALTER PROCEDURE sp_AllCurrentUs ers
/*
Name: sp_AllCurrentUs ers
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 1580
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_Accou ntMonitor.Commo nUtilities
SelectMethod FillDataGrid
Select Parameters Name spName Value sp_DepartmentLi st

Tier 2 - business layer

Imports System.Data.Sql Client

Namespace RC_Web_AccountM onitor

Public Class CommonUtilities
Public Sub New()

End Sub

Public Function FillDataGrid(By Val spName As String) As DataSet
Dim dsDataGrid As DataSet

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

End Function

End Class

End Namespace

Tier 3 - data layer

Imports System.Data.Sql Client

Public Class DBConnection

Private _ParamList As SqlParameterCol lection
Private _MyComm As New SqlCommand

Private _ConnectionStr As String =
ConfigurationMa nager.Connectio nStrings("Conn" ).ToString

'shared connection
Dim conn As New SqlConnection(_ ConnectionStr)

Public Sub New()

End Sub

Public Function GetDatasetFromS P(ByVal SPName As String) As DataSet

Dim Myds As New DataSet

Dim MyAdapter As New SqlDataAdapter( _MyComm)
_MyComm.Command Type = CommandType.Sto redProcedure
_MyComm.Command Text = SPName

_MyComm.Connect ion = conn
Try
MyAdapter.Fill( Myds, "Results")
Catch ex As Exception
System.Web.Http Context.Current .Session("DBErr or") = "True"
System.Web.Http Context.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_Accou ntMonitor.Commo nUtilities
SelectMethod FillDataGrid
Select Parameters Name spName Value sp_DepartmentLi st

Tier 2 - business layer

Imports System.Data.Sql Client

Namespace RC_Web_AccountM onitor

Public Class CommonUtilities
Public Sub New()

End Sub

Public Function FillDataGrid(By Val spName As String) As DataSet
Dim dsDataGrid As DataSet

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

End Function

End Class

End Namespace

Tier 3 - data layer

Imports System.Data.Sql Client

Public Class DBConnection

Private _ParamList As SqlParameterCol lection
Private _MyComm As New SqlCommand

Private _ConnectionStr As String =
ConfigurationMa nager.Connectio nStrings("Conn" ).ToString

'shared connection
Dim conn As New SqlConnection(_ ConnectionStr)

Public Sub New()

End Sub

Public Function GetDatasetFromS P(ByVal SPName As String) As DataSet

Dim Myds As New DataSet

Dim MyAdapter As New SqlDataAdapter( _MyComm)
_MyComm.Command Type = CommandType.Sto redProcedure
_MyComm.Command Text = SPName

_MyComm.Connect ion = conn
Try
MyAdapter.Fill( Myds, "Results")
Catch ex As Exception
System.Web.Http Context.Current .Session("DBErr or") = "True"
System.Web.Http Context.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
28567
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 flags = (BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance | BindingFlags.DeclaredOnly); //Iterate through the Assembly to find Class with a Public Interface.
4
7246
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 function in the world at birth. Defining a parameterless constructor allows it to be created in an unstable state. On the other hand
12
8983
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. Let me mention two cases where I wanted parameterless struct constructors but could not get them. 1st, I needed sortable identity stamps on certain classes of
0
1261
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 table Items. Since the dataset code is constructed by the IDE why am I getting this error and how do I correct it?
1
2645
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 shows the following error on the control in the designer: Error Creating Control - No parameterless constructor defined for this object I have defined four New methods. Although none of them are simply Public Sub New(), one of them has just one...
3
1623
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 expected... Dim x as New String()
2
1654
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 constructor of a baseclass is also executed (before your own construcor executes). If you don't call one explicitly, the parameterless constructor is called automatically. I don't know what the VB syntax is. In C# it would be something like:
2
3271
by: bednarz.thomas | last post by:
I have the following business Object(s): public class ParentObject { public ParentObject(string somestring) { ...- } ....
9
2689
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, relying on the compiler to do the right thing underneath." Does it mean that if we create a Value type with other constructors, we will still have a parameterless constructor provided by compiler?
0
8600
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9155
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9018
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8890
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8858
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7711
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4614
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3038
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2322
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.