1 //real name Save2$ ("#TrueNameSaveBtn"). Click (function () {3 if($ ("#TrueNameSaveText"). val ()! = "") {4 //Uploading Data5$.post ("/home/updateuserinfo", {"Item": "Truename", "Data": $ ("#TrueNameSaveText"). Val ()},function(Result) {6 if(Result = = "Success") {7$ ("#TrueNameErrorMsg"). Text ("* Save successful *");8 9}Else if(Result = = "Error") {Ten$ ("#TrueNameErrorMsg"). Text ("* Save failed *"); One } A }); -}Else { -$ ("#TrueNameErrorMsg"). Text ("* text box cannot be empty *"); the - } -});
The above is the JS code
The following is the C # code
1 PublicActionResult Updateuserinfo (stringItemstringdata)2 {3 if(session["username"] !=NULL)4 {5 stringsql ="Update UserInfo Set @item = @data where (LoginId = @LoginId or Email = @LoginId)";6 Try7 {8 using(SqlConnection con =NewSqlConnection (connstr))9 {Ten con. Open (); One using(SqlCommand cmd =con. CreateCommand ()) A { -Cmd.commandtext =SQL; -Cmd. Parameters.Add (NewSqlParameter ("@data", data)); theCmd. Parameters.Add (NewSqlParameter ("@item", item)); -Cmd. Parameters.Add (NewSqlParameter ("@LoginId", (string) session["username"])); - - if(CMD. ExecuteNonQuery () >0) + { - returnContent ("Success"); + } A Else at { - returnContent ("Error"); - } - } - } - } in Catch(Exception e) - { to Throwe; + } - } the Else * { $ returnContent ("Error");Panax Notoginseng } -}
Return is success, but viewing the database does not update the data
The ExecuteNonQuery () return value of ASP. NET successfully performed update is greater than 0, but the view database has not changed