vb.net - Calling sql server stored procedure from VB 2008 with two outbound parameters -
stored procedure return recordset , 2 results. when executed sql server management studio returns recordset , value @numitems , value @reason. when called vb @reason 0 @numitems when should return @@rowcount 4. @reason coming value of "ok" @numitems coming 0.
end of sproc has
set @numitems = @@rowcount set @reason = 'ok' -- process completed @ end. recordset when executed has 4 rows , @numitems has returnvalue of 4 in sql server any ideas?
dim dt new datatable dim da new sqlclient.sqldataadapter dim strconnection string = "" strconnection = strconnectioninfo dim sqlcommand new sqlcommand dim sqlconnection new sqlconnection sqlconnection.connectionstring = strconnection sqlconnection.open() try sqlcommand .commandtype = commandtype.storedprocedure .commandtext = "dbo.sprestockminmax" .parameters.add("@numitems", sqldbtype.bigint).direction = parameterdirection.output .parameters.add("@reason", sqldbtype.varchar, 20).direction = parameterdirection.output .connection = sqlconnection end sqlcommand.executescalar() 'dim numitems long = sqlcommand.parameters("@numitems").value.tostring da.selectcommand = sqlcommand da.fill(dt) dv = new dataview(dt) me.dgminmaxreplenish.datasource = dv dim myreason string = sqlcommand.parameters("@reason").value.tostring dim numitems long = sqlcommand.parameters("@numitems").value.tostring if ucase(myreason) = "ok" if numitems > 0 msgbox("replenishment list created " & numitems & " added replenishment", msgboxstyle.information, "replenishment list created") else msgbox("no items found needing replenishment", msgboxstyle.information, "no items needed") end if else msgbox("something happenned during stored procedure", msgboxstyle.critical) end if catch ex exception txtsystemmessages.text = ex.message end try if dgminmaxreplenish.rowcount > 1 dgminmaxreplenish.visible = true end if
i have no idea stored procedure internally, running 2 times. first time in executescalar call, second time in fill call , read output parameters after second call. procedure produces different output when called in sequence , without changes underlying data.
so, perhaps remove call executescalar , run directly fill call
Comments
Post a Comment