newbie Q on null reference

C

Co

Hi All,

I'm new on dotnet and I have some function that give me a warning that
my code doesn't return a result on all code paths, I should have a
null reference exeption:

Private Function PopulateStatus()

Dim sql = "SELECT * FROM Status"
Dim cmd As New OleDbCommand(sql, conn)
Dim dr As OleDbDataReader
dr = cmd.ExecuteReader()

Try
While dr.Read()
cboStatus.Items.Add(dr.Item("status"))
End While
Catch Ex As Exception

End Try

End Function

How do you create something like that?

Regards
Marco
The Netherlands
 
A

Armin Zingler

Co said:
Hi All,

I'm new on dotnet and I have some function that give me a warning that
my code doesn't return a result on all code paths, I should have a
null reference exeption:

Private Function PopulateStatus()

As ....?

Do you have Option Strict On?
Dim sql = "SELECT * FROM Status"
Dim cmd As New OleDbCommand(sql, conn)
Dim dr As OleDbDataReader
dr = cmd.ExecuteReader()

Try
While dr.Read()
cboStatus.Items.Add(dr.Item("status"))
End While
Catch Ex As Exception

End Try

End Function

How do you create something like that?

Create what? The problem is that the function does not return a value.


Armin
 
C

Co

 As ....?

Do you have Option Strict On?










Create what? The problem is that the function does not return a value.

Armin

No I don't have Strict On.
So if a function doesn't return a value but simply perform a task it
should become a Sub?
Is that what you are saying?

Marco
 
H

Herfried K. Wagner [MVP]

Co said:
No I don't have Strict On.

I suggest to turn it on -- it will enable to compiler to make you aware of
certain hard-to-find problems with your source code.
So if a function doesn't return a value but simply perform a task it
should become a Sub?

Exactly.
 
A

Armin Zingler

Co said:
No I don't have Strict On.

Menu Extras -> Options: Projects and solutions -> VB defaults: Option Strict
On.

Do the same in your project's properties.
So if a function doesn't return a value but simply perform a task it
should become a Sub?
Is that what you are saying?

Yes.

Have you conidered learning the language first? This group is not a
substituion. If you don't like the documentation, there are plenty of books
out there.


Armin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top