c# - ObjectContext.ExecuteStoreCommand doesn't recognise parameter -
what doing wrong here?
... using (var ctx = objectcontextmanager<mydatacontext>.getmanager("mydatacontext")) { var idstoupdate = "2,3"; var parameters = new[] { new sqlparameter("desiredenddate", sqldbtype.datetime).value = newupperlimit, new sqlparameter("taskstoupdate", sqldbtype.nvarchar).value = idstoupdate }; ctx.objectcontext.executestorecommand("update dbo.tasks set desiredenddate = @desiredenddate id in (select id dbo.fn_split(@taskstoupdate, n','))", parameters); ctx.objectcontext.savechanges(); } ...
i error
must declare scalar variable "@desiredenddate".
must declare scalar variable "@taskstoupdate".
but cannot see wrong code :/
the problem code:
var parameters = new[] { new sqlparameter("desiredenddate", sqldbtype.datetime).value = newupperlimit, new sqlparameter("taskstoupdate", sqldbtype.nvarchar).value = idstoupdate };
is not creating array of sqlparameter
s - it's create array of 2 value
properties. can confirm changing code (which not compile):
var parameters = new sqlparameter[] { new sqlparameter("desiredenddate", sqldbtype.datetime).value = newupperlimit, new sqlparameter("taskstoupdate", sqldbtype.nvarchar).value = idstoupdate };
and (which compile)
var parameters = new sqlparameter[] { new sqlparameter("desiredenddate", sqldbtype.datetime), new sqlparameter("taskstoupdate", sqldbtype.nvarchar) }; parameters[0].value = newupperlimit; parameters[1].value = idstoupdate;
you can this:
var param1 = new sqlparameter("desiredenddate", sqldbtype.datetime); param1.value = newupperlimit; var param2 = new sqlparameter("taskstoupdate", sqldbtype.nvarchar); param2.value = idstoupdate; ctx.objectcontext.executestorecommand("...", param1, param2);
Comments
Post a Comment