Total newbie, getting error "Reference to a non-shared member requiresan object reference."

  • Thread starter Thread starter doofy
  • Start date Start date
D

doofy

I'm trying to jump start with VB.Net/Ado.Net to get something done at
work.

I'm using the book "Programming Microsoft ADO.Net 2.0". One problem
with this book is that his sample code does not spell out the imports.
Usually somewhere in the paragraphs or pages before, it says "This
assumes you're importing blah.blah.blah."

Well, I'm not finding the reference.

I've used the Data Source Configuration wizard to create BisDataSet.

It's blowing up on line 9, on "BisDataSet" saying "Reference to a
non-shared member requires an object reference."

Trying to look that error message up on the Microsoft gives me a generic
definition and little to go on.

Here's my code:

Imports Microsoft.Office.Interop.Excel
Imports Microsoft.SqlServer.Server
Imports System.Data.SqlClient
Imports System.Data

1 Module Module1
2
3 Sub Main()
4
5 End Sub
6 Sub write_Scorecard_RRTP()
7
8 Dim RRTPRowset As BisDataSet.RRTP_ScorecardRow()
9 RRTPRowset = BisDataSet.RRTP_Scorecard(0)
10
11 End Sub
12 End Module
 
doofy said:
I'm trying to jump start with VB.Net/Ado.Net to get something done at work.

I'm using the book "Programming Microsoft ADO.Net 2.0". One problem
with this book is that his sample code does not spell out the imports.
Usually somewhere in the paragraphs or pages before, it says "This
assumes you're importing blah.blah.blah."

Well, I'm not finding the reference.

I've used the Data Source Configuration wizard to create BisDataSet.

It's blowing up on line 9, on "BisDataSet" saying "Reference to a
non-shared member requires an object reference."

Trying to look that error message up on the Microsoft gives me a generic
definition and little to go on.

Here's my code:

Imports Microsoft.Office.Interop.Excel
Imports Microsoft.SqlServer.Server
Imports System.Data.SqlClient
Imports System.Data

1 Module Module1
2
3 Sub Main()
4
5 End Sub
6 Sub write_Scorecard_RRTP()
7
8 Dim RRTPRowset As BisDataSet.RRTP_ScorecardRow()
9 RRTPRowset = BisDataSet.RRTP_Scorecard(0)
10
11 End Sub
12 End Module

Never mind. I just sort of went the manual route and built my own
connection string.
 
doofy,

As soon as you write "As" in VB for Net and it is not a value, then you need
to call the sub New in the called class to construct it. (The same for C#,
however there the constructor is created with a method without type or
void). Be aware that if the Sub New (constructor) is not in the called class
then the default empty constructor is used.

Which means
(This one above can be protected (probably is) and then you get a message
back)

Cor
 
Cor Ligthert said:
doofy,

As soon as you write "As" in VB for Net and it is not a value, then you
need to call the sub New in the called class to construct it. (The same
for C#, however there the constructor is created with a method without
type or void). Be aware that if the Sub New (constructor) is not in the
called class then the default empty constructor is used.

Which means
(This one above can be protected (probably is) and then you get a message
back)

If on row 9 he is assigning to the variable RRTPRowset , why would he
on row 8 assign a New object to it only to discard that.

There was nothing wrong with the two lines of code he wrote except that
BisDataSet was referring to the class name when it needs to be referring to
an instance (either declared inside the method or globably available)
 
Bill,
If on row 9 he is assigning to the variable RRTPRowset , why would he
on row 8 assign a New object to it only to discard that.

There was nothing wrong with the two lines of code he wrote except that
BisDataSet was referring to the class name when it needs to be referring
to
an instance (either declared inside the method or globably available)

I have never known that you can use an object as a type, however as you say
it, than it will probably be like that.
Still I keep using only classes and valuetypes when I use "AS".

Therefore the so by you beloved "Dim" is in fact here only legacy sugar AS
I have often written in other discussions with you

If there was written in VB 2008 with option Infer on,

\\\
Dim RRTPRowset = BisDataSet.RRTP_ScorecardRow()
///

Then I could have used it, because than it is nothing more than a result
from a method confirm the returning type of that method.

However it could in my idea be an improvement for the next version of VB as
by instance

\\
RRTPRowset As BisDataSet.RRTP_ScorecardRow()
///

Would be to instance a class or value in VB, in fact is nothing else needed
and giving not any breaking change because this code did never exist.

Cor
 
Bill,

Correction, you can be right, somehow my brain was not working well at the
moment I wrote this.

Cor
 
Back
Top