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 sqlparameters - 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

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -