asp.net mvc - How to update a table row, given the RowID and the Value to update. MVC C# Linq -
here code. paypal sends actionresult rowid item_number
, transaction id pp_txn_id
. simple want reference row in transaction table, tblpaypaltransactions
, , update pp_txn_id
see sent me after purchase in paypal. photo links sent downloadpicture.cshtml
view.
i can't figure syntax out update transaction table. else can do. stuck here trying finish project.
//row in photos item_number, paypal paid transaction pp_txn_id public actionresult thankyou(string item_number, string pp_txn_id) { var photo = db.paypaltransactions.where(x => x.rowid == convert.toint32(item_number)); photo.pp_txn_id = pp_txn_id; db.submitchanges(); var thispaidphoto = (from p in db.photos p.photoid == convert.toint32(item_number) select p).firstordefault(); return view(thispaidphoto); }
your current code have compilation errors because where
method returns collection. photo
variable collection type , not have pp_txn_id
property.
assuming rowid unique identifier of record in table, need single record.
you may use firstordefault
method.
var rowid=convert.toint32(item_number) var photo = db.paypaltransactions.firstordefault(x => x.rowid ==rowid); if(photo!=null) { // update photo.pp_txn_id = pp_txn_id; db.submitchanges(); } else { // item not exist in table. handle needed. }
also keep in mind that, convert.toint32
method throw exception if input not valid numeric value. use int32.tryparse
safe. if sure values going numeric type, recommend use numeric type param (int
or long
).
Comments
Post a Comment