Hi guys,
I am embarking on a new project and using the CSLA for the frst time in a business environment...
I apologize in advance for what I suspect is a really stupid question, and possibly the weather is causing me not to think straight...
What I am trying to do - is create a function based within my "customer" business object that will ultimately return a string message and am having problems trying to implement it.
Basically, it need to call a stored procedure that returns a string value based on the customer# criteria. I have tried to implement something along the lines of the "exists" function using commandbase, but I don't have an example of how this is implemented (in ProjectTracker?). If I try to call from my windows form with something like this...
mystatus = customer.getmystatus(customerno)
the compiler is saying "Access of shared member, constant member, enum member or nested type through an instance; qualifying expression will not be evaluated."
Am I barking up the wrong tree? Should I be approaching this in a different way?
Any help/suggestions would be much appreciated.
Thanks,
Graham
Here's the code I have in my customer business object.... if it's any help..
#
Region " Get Status" Public Shared Function GetStatus(ByVal customerno) As String Dim result As GetStatusCommandresult = DataPortal.Execute(
Of GetStatusCommand)(New GetStatusCommand(customerno)) Return result.myStatus End Function<Serializable()> _
Private Class GetStatusCommand Inherits CommandBase Private mCUSTOMERNO As String Private mMyStatus As String Public ReadOnly Property myStatus() As String Get Return mMyStatus End Get End Property Public Sub New(ByVal customerno As String)mCUSTOMERNO = customerno
End Sub Protected Overrides Sub DataPortal_Execute() Using cn As New SqlConnection(Database.crm2k6Connection)cn.Open()
Using cm As SqlCommand = cn.CreateCommandcm.CommandType = CommandType.StoredProcedure
cm.Parameters.AddWithValue(
"@CustomerNo", mCUSTOMERNO)cm.Parameters.AddWithValue(
"@ContactNo", "")cm.Parameters.AddWithValue(
"@SiteNo", "")cm.Parameters.AddWithValue(
"@Status", mMyStatus)cm.Parameters.AddWithValue(
"@Flag", "")cm.Parameters.AddWithValue(
"@OptArg", "")cm.Parameters(
"@Status").Direction = ParameterDirection.Outputcm.CommandText =
"C2K6_getstatus"cm.Parameters.AddWithValue(
"@CUSTOMERNO", mCUSTOMERNO)cm.ExecuteNonQuery()
mMyStatus =
CType(cm.Parameters("@Status").Value, String) End Using End Using End Sub End Class#
End Region
I thought I might be ... (darn tree)...
I thought I had approached it correctly by placing the sub/function in my business class a la the obj.exists method - is this not a command? I do want to use the dataportal for this type of thing absolutelty,
I used the string value as a simplified example - I am in fact calling a stored procedure that runs off to another application to trigger a new order - the stored proc, merely returns a completion status (0=successfully populated the order entry module with data, 1=failed, etc...). So the value itself isn't persistent - I only need the value (and can only request it) when I want to 'place an order'.
Any help to put me on track would be appreciated...
thx,
gajit
i thought so.. :)... well.. i had a suspicion... but didn't want to upset the boss :)
Thanks Rocky ... no problem - good to know I'm on the right track - and incidentally - it works. I was trying to call an using a instance of the class and not the class itself.
Onwards I go....
gajit.
RockfordLhotka:
Data access code should always go into a DataPortal_XYZ method, or into a server-side data access assembly that is only called by a DataPortal_XYZ method.
I haven been thinking to seperate the data access routines into a assembly that only gets installed on the server. For two reasons, I can make changes to this code and only have to install a new DLL on the server, and second is kind of reducing risk of having something on the client that tells how the databse is imlpemented and could be disassembled.
So my question is do you have any thoughts on how to implement a server-side data access assemply. I would need to dynamically load this DLL so the client wouldn't have any referernces to it? I am thinking that the client execuatable can't have a reference to this DLL if it is not installed on the client.
ktweedy:So my question is do you have any thoughts on how to implement a server-side data access assemply. I would need to dynamically load this DLL so the client wouldn't have any referernces to it? I am thinking that the client execuatable can't have a reference to this DLL if it is not installed on the client.
Copyright (c) Marimer LLC