The ExecuteNonQuery () return value of ASP. NET successfully performed update is greater than 0, but the view database has not changed

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.