ASP Components Intermediate beginner and Proficient Series VII

Source: Internet
Author: User
Start the database operation.





Common Component Encapsulation





1.? Encapsulate the connection information of the database.





1>???? Return directly to the database connection string, such as
in the component




public? Function? DataSource ()? As? Variant





datasource? =? "Driver={sql?" server};server=yang;uid=sa;pwd=;? Database=northwind "





end? Function





?





ASP Call





set Obj=server. CreateObject ("Webdb.getinfo")??





Oconn=obj.datasource ()





This shortcoming is very obvious, in the ASP file, the direct Response.Write oconn can display the database connection string, does not have the anticipated function.





?





2>???? Returns the Adodb.connection object





public Function Getconn () as ADODB. Connection





Set conn = New ADODB. Connection





Conn. ConnectionString = "Provider=SQLOLEDB.1; Persist Security Info=false; User id=sa;password=;initial catalog=northwind;data Source=yang "





Conn. Open





Set getconn = conn





End Function





?





ASP Call





Dim dataquery





Set dataquery=server.createobject ("Webdbtest.getinfomation")





set Rs=server.createobject ("Adodb.recordset")





?





sql= "SELECT * FROM Employees"





Rs.Open sql,dataquery.getconn,1,3???





?





Response. Write Rs ("LastName")





Response.Write DataQuery.getconn.ConnectionString





Set rs=nothing





?





this looks good, just Response.Write DataQuery.getconn.ConnectionString or will display a database connection string, we can test.





?





?





?





2.? Encapsulate a component to a recordset





You can take a look at the http://blog.csdn.net/online/archive/2003/12/11/7764.aspx
you wrote some time ago.




This piece of code is not a good point is that the database connection to the page to judge, after the successful connection, before starting to access data, see








?





?





personally think that the best thing to do is:





encapsulation to the Recordset, the component method to connect the database, after the operation, timely shutdown





as much as possible to generate HTML code in the component, do all encapsulation. As in the following way








rather than part of the package.











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.