sql server - Why does my VB.NET Function shows a warning -


  public function delete_gst_entry(byval ge_id integer) datatable     try         using con new sqlconnection(df_class.getconnectionstring())             dim ds datatable = new datatable             con.open()             dim command sqlcommand = new sqlcommand("delete_gstentry", con)             command.parameters.addwithvalue("ge_id", ge_id)             command.commandtype = commandtype.storedprocedure             dim adapter sqldataadapter = new sqldataadapter(command)             dim table datatable = new datatable             adapter.fill(ds)             return ds              con.close()         end using     catch ex sqlexception         messagebox.show(ex.message, "data input error")      end try  end function 

i getting warning saying null reference occur. mistake doing?

warning:

"function 'delete_gst_entry' doesn't return value on code paths. null reference exception occur @ run time when result used. "

all exit points (return paths) of method must return method's signature specifies.

re-write this:

public function delete_gst_entry(byval ge_id integer) datatable    dim dt datatable = new datatable     try         using con new sqlconnection(df_class.getconnectionstring())              con.open()             dim command sqlcommand = new sqlcommand("delete_gstentry", con)             command.parameters.addwithvalue("ge_id", ge_id)             command.commandtype = commandtype.storedprocedure             dim adapter sqldataadapter = new sqldataadapter(command)             adapter.fill(dt)             con.close()         end using     catch ex sqlexception         messagebox.show(ex.message, "data input error")     end try      return dt    ' note empty if stored proc call fails... end function 

ideally, should wrap connection in using statement.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -