i hope below stored procedure inserts new record table , returns same when executed. tried utilize stored procedure entity framework shown far below. new record inserted. don't know why couldn't value returned procedure.
stored procedure:
use [materials] go create procedure [dbo].[insertquery1] @code nvarchar(50), @name nvarchar(100) begin insert dbo.materials (code, name) values (@code, @name) select mat.id, mat.code, mat.name dbo.materials mat mat.id = scope_identity() end
aspx.vb code:
protected sub testing_click(sender object, e eventargs) dim code string dim name string dim element object code = "new code" name = "new element" element = ent.insertquery(code, name) dim mat material = ctype(element, material) end sub
when try code, following error
unable cast object of type 'system.data.objects.objectresult`1[stored_procedure_test.insertquery_result]' type 'stored_procedure_test.material'.
at line dim mat material = ctype(element, material)
it clear exception casting , object of stored_procedure_test.insertquery_result
object type of material
. sp returns collection of objects of type stored_procedure_test.insertquery_result
. can value object returned sp this.
stored_procedure_test.insertquery_result element = ent.insertquery(code, name).firstordefault(); //and can access properties of object string name=element.name;
so complete code should this
protected sub testing_click(sender object, e eventargs) dim code string dim name string code = "new code" name = "new element" dim element stored_procedure_test.insertquery_result = ent.insertquery(code, name).firstordefault(); //now can directly use `element` access values returned sp. end sub
Comments
Post a Comment