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,