I would like to add 2 variables in Razor C#.
Therefore I tried this:
var newpenpoints = result.PenaltyPoints + int.Parse(penalty);
But I think it is not working as when I try to put the figure into database:
var sql5 = "UPDATE Permit SET PenaltyPoints=@0, Disqualification = @1, LastAccidentDate = @2 WHERE CDSID = @3";
var para1 = new{newpenpoints, disqualification, dateocc, empcdsid};
db.Execute(sql5,para1);
Response.Redirect("~/AccidentConviction");
There was en error:
CS0746: Invalid anonymous type member declarator. Anonymous type members must be declared with a member assignment, simple name or member access.
Does anyone know how can I amend my code to make it do some maths?
Thanks
This is not valid code:
This is trying to create an anonymous type]1 with four fields, but you are not giving them names. To create this kind of type, you must either initialize the fields with values from another object that you already have, or else name them explicitly:
However, re-reading your sample code, it suspect what you really want is an array of objects. You don’t say what
dbis in this case but I’m guessing thatExecutetakes astringand anobject[]for parameters. In that case, what you want is:Note the
[]: this is creating a new array of objects with the list of values in it, e.g.para1[0] = newpenpoints, etc. I think this is what you really meant to do.