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

Reference to a non-shared member requires an object reference

Hi,

I'm creating small aspnet application. The main purpose of application
is to manage list of contracts (adding, updating, deleting) and
creating reports based on database of contracts. So I've created a
class Contract, which have all contract's properties and method like
InsertContract etc. In my InsertContract method I want to pass Contract
object to my database provider class Insert method. I'm receiving an
error "Reference to a non-shared member requires an object reference".
It's understandable, because I didn't instantiate database provider
object before. I can workaround this error using "shared" keyword in my
database provider method definition. My question is, if it's correct
solution and if not, what shall I do. Here is my code:

Public Class Contract

Public Property Trademark() As String
Get
Return _trademark
End Get
Set(ByVal value As String)
_trademark = value
End Set
End Property

' other properties

Public Sub New()

End Sub

'other methods

Public Sub InsertContract ()
DatabaseProvider.InsertContract (contract)
End Sub

End Class
Public Class DatabaseProvider

Public Shared Sub InsertContract (record as Contract)

'adding contract to database

End Class

Przemek

Sep 19 '06 #1
1 4061
>
I'm creating small aspnet application. The main purpose of application
is to manage list of contracts (adding, updating, deleting) and
creating reports based on database of contracts. So I've created a
class Contract, which have all contract's properties and method like
InsertContract etc. In my InsertContract method I want to pass Contract
object to my database provider class Insert method. I'm receiving an
error "Reference to a non-shared member requires an object reference".
It's understandable, because I didn't instantiate database provider
object before. I can workaround this error using "shared" keyword in my
database provider method definition. My question is, if it's correct
solution and if not, what shall I do. Here is my code:

Public Class Contract

Public Property Trademark() As String
Get
Return _trademark
End Get
Set(ByVal value As String)
_trademark = value
End Set
End Property

' other properties
Several things here, mainly design issues. I would make "InsertContract" a
method on your Database provider. So you pass in a Contract object to the
provider, rather than try to make the contract itself "know" about the
provider ( ie. "myProvider.InsertContract ( myContract ). If you want to do
the latter, you need to store an reference to the provider in the contract,
which I'm sure you will agree is not quite so easy to do. You could of
course make your provider a global singleton, and then reference it with
your contract object, but I don't think that would be a very good idea.

Sep 19 '06 #2

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

Similar topics

12
by: lothar | last post by:
re: 4.2.1 Regular Expression Syntax http://docs.python.org/lib/re-syntax.html *?, +?, ?? Adding "?" after the qualifier makes it perform the match in non-greedy or minimal fashion; as few...
3
by: Mario | last post by:
Hello, I couldn't find a solution to the following problem (tried google and dejanews), maybe I'm using the wrong keywords? Is there a way to open a file (a linux fifo pipe actually) in...
1
by: Markus Ernst | last post by:
Hi I wrote a function that "normalizes" strings for use in URLs in a UTF-8 encoded content administration application. After having removed the accents from latin characters I try to remove all...
4
by: bwmiller16 | last post by:
Guys - I'm doing a database consistency check for a client and I find that they're building unique indexes for performance/query reasons where they could be using non-unique indexes. Note...
0
by: Christopher Attard | last post by:
Hi, I need to create a dialog like the 'Add Counters' dialog box in perfmon. I'm using the System.Diagnostics namespace class in .NET and I've managed to do it. The problem arises when I'm...
0
by: Henry Wu | last post by:
Hi, I am aware that TransparencyKey only works with top-level forms or Non-MDI Child Forms, if one tries to set the opacity or transparencykey property to a MDI-Child form, it will have no effect....
13
by: Academic | last post by:
I have a MDI form, sometimes child forms and sometimes forms that are neither If I close the app the child forms closing and closed event happens followed by the Mdi form receiving the...
0
by: amitvps | last post by:
Secure Socket Layer is very important and useful for any web application but it brings some problems too with itself. Handling navigation between secure and non-secure pages is one of the cumbersome...
399
by: =?UTF-8?B?Ik1hcnRpbiB2LiBMw7Z3aXMi?= | last post by:
PEP 1 specifies that PEP authors need to collect feedback from the community. As the author of PEP 3131, I'd like to encourage comments to the PEP included below, either here (comp.lang.python), or...
12
by: puzzlecracker | last post by:
is it even possible or/and there is a better alternative to accept input in a nonblocking manner?
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
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
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...

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.