Create ASP.net test page
Creating a test page is always a good way to access the SQL Server data tier and verify that input and output parameters are handled correctly. In fact, this is the only way to ensure that asp.net pages and components in future production solutions work as expected. This is especially true for authentication trust boundaries and security issues when calling other tiers from a layer in the solution.
Also, do not rigidly adhere to the creation of a production class interface when testing. You only need to test the target method. In fact, deliberately creating "ugly" test pages that you don't want to be a final production solution is a good strategy! In this article, I created some very simple asp.net pages that contain a list of test records and an input form for adding, editing, and deleting Test records.
For example, the following is the WebForm layout used to test topic records. You will notice that it contains the status label for the error message or other message, the record Count label, the data grid that displays the list of records, the input box for the record ID used to enter the retrieval, and the small table that supports adding, editing, and deleting records (see Figure 10).
Figure 10: WebForm layout for testing the subject record
When you create a test page, it's best to keep your code simple and straightforward. I usually add a small piece of code to each button to call the local method to handle the database operation. The following is the code for the Get record (Fetch Records) button on the Topictest.aspx page.
Private Sub Btngettopic_click (ByVal sender as System.object,byval e as System.EventArgs) Handles Btngettopic.click
Try
Dim ID as Integer = Int32.Parse (Txqueryid.text)
GetItem (ID) ' for database calls
Txid.text = Txqueryid.text
Txtitle.text = Mtitle
Txdescription.text = Mdescription
Lbstatus.text = "success!"
Catch ex as Exception
Lbstatus.text = ex. Message
End Try
End Sub
Note that the only action actually performed in this method is handled by the GetItem (ID) method call. It executes the database call and sets the local variable with the value returned. The following is the code for the GetItem method. Note that it uses a large number of SqlParameter objects to handle input and output values.
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