newbie Q on null reference

  • Thread starter Thread starter Co
  • Start date Start date
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
 
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
 
 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
 
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.
 
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
 
Back
Top