ASP. NET data verification judgment and prompts at different stages

Source: Internet
Author: User
ASP. NET data verification judgment and prompts at different stages
It is still a bit of trouble to perform data verification and prompt on the web.
1: In the page entry control, you can use the verification control
2: In the Dal (reference http://www.asp.net/learn/dataaccess/tutorial18cs.aspx? Tabid = 63)
 Protected   Void Gridview1_rowupdated ( Object Sender, gridviewupdatedeventargs e ){ If (E. Exception! = Null ){ // Display a user-friendly message Predictiondetails. Visible = True ; Exceptiondetails. Text =" There was a problem updating the product. ";If (E. Exception. innerexception! = Null ) {Exception inner = E. Exception. innerexception; If (Inner Is System. Data. Common. dbexception) exceptiondetails. Text + =" Our database is currently experiencing problems. Please try again later. "; Else   If (Inner Is Nonullallowedexception) exceptiondetails. Text + =" There are one or more required fields that are missing. "; Else  If (Inner Is Argumentexception ){ String Paramname = (argumentexception) Inner). paramname; predictiondetails. Text + = String . Concat (" The ", Paramname ," Value is illegal. ");} Else   If (Inner Is Applicationexception) exceptiondetails. Text + = Inner. Message ;} // Indicate that the exception has been handled E. exceptionhandled = True ; // Keep the row in edit mode E. keepineditmode = True ;}}

3: In BLL

 Public   Bool Updateproduct ( String Productname, Decimal ? Unitprice, Short ? Unitsinstock, Int Productid) {northwind. productsdatatable products = Adapter. getproductbyproductid (productid ); If (Products. Count = 0) // No matching record found, return false Return   False ; Northwind. productsrow Product = products [0]; // Make sure the price has not more than doubled  If (Unitprice! = Null &&! Product. isunitpricenull ()) If (Unitprice> product. unitprice * 2) Throw   New Applicationexception (" When updating a product price, "+" The new price cannot exceed twice the original price. "); Product. productname = productname;If (Unitprice = Null ) Product. setunitpricenull (); Else Product. unitprice = unitprice. value; If (Unitsinstock = Null ) Product. setunitsinstocknull (); Else Product. unitsinstock = unitsinstock. value; // Update the product record  Int Rowsaffected = Adapter. Update (product ); // Return true if precisely one row was updated, otherwise false  Return Rowsaffected = 1 ;}

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.