Dataset question

  • Thread starter Thread starter tiger79
  • Start date Start date
T

tiger79

Hi,
I've got the following problem :
I made an api which is referenced by program1. In this API i have a method
(called Retrieve) in which I create a Dataset and fill a DataTable with data
out of a DataBase. This method returns the DataSet. While calling this
DataSet I allso supply two integer values (for search purposes in the
sql-query in the method).
My problem now is that when I call this method in program1 and try to assign
the returned value (thus de Dataset) I get the following error :
An object reference is required for the nonstatic field, method, or property
'Dictionarytest1.peccAttributeValues.Retrieve(int, int)'

I use this code for assigning :
DataSet myDataSet =
Dictionarytest1.peccAttributeValues.Retrieve(AttributeId, Level);

Like i've allways did when I assign like an integer or whatever...

Any idea what the problem is about ? Or if its better to implement something
else ?
If it's helpful I can always post some code...
 
Try this:

DataSet myDataSet = new DataSet();
myDataSet = Dictionarytest1.peccAttributeValues.Retrieve(AttributeId,
Level);

--Neil
 
hhhmmm... that one i allready tried, I dont understand still get the same
error : An object reference is required for the nonstatic field, method, or
property 'Dictionarytest1.peccAttributeValues.Retrieve(int, int)'
 
For an instance method (not static) you need to create an instance of your
type and then call the method on it e.g.

Dictionarytest1.peccAttributeValues myAttVals = new
Dictionarytest1.peccAttributeValues();

DataSet myDataSet = myAttVals.Retrieve(AttributeId, Level);

This is assuming that "Dictionarytest1.peccAttributeValues" is the name of
your custom object which I am assuming based on the error you are receiving.
If your retrieve method has no need to use instance information from the
class it is defined in you can declare it as static in your custom api and
you will not need to create an instance of the class before calling the
method.

Peter
 
OK, can you show us some code?

--Neil


tiger79 said:
hhhmmm... that one i allready tried, I dont understand still get the same
error : An object reference is required for the nonstatic field, method,
or
property 'Dictionarytest1.peccAttributeValues.Retrieve(int, int)'
 
Thanx Peter, it works now :D
hehehe... it's typical though, that I didnt think of it myself and then
while reading ur answer thinking thats logical !!! ;)
 
gonna ask something offopic now :
if i try to add a node to a treeview, but I allways get the
nullreferencexception error : An unhandled exception of type
'System.NullReferenceException' occurred in TestAttributeValues.exe
what does that mean ? I mean i'm not trying to reference some index or
whatever, even when i try to do the clerar() method i get the same error...
 
Got some code?

--Neil


tiger79 said:
gonna ask something offopic now :
if i try to add a node to a treeview, but I allways get the
nullreferencexception error : An unhandled exception of type
'System.NullReferenceException' occurred in TestAttributeValues.exe
what does that mean ? I mean i'm not trying to reference some index or
whatever, even when i try to do the clerar() method i get the same
error...
 
hehehe..
I allready found it ;)
I was referncing the treeview in a method which was called before the
initlializecomponent() ;)

poor me, its not my day :(
 
Back
Top