asp.net Web Development Package Wq.dll Packaging Download _ Practical Tips

Source: Internet
Author: User
Tags connectionstrings
It is not that I do not open source, I think it is easier to wrap up, I did not encrypt, to see the source code directly reversed to see.
All Wq objects, sorted by their function, are placed under 5 different namespaces:

Copy Code code as follows:

Using WQ. data;//Database Operations Class
Using WQ. rewriter;//pseudo URL Configuration class
Using WQ. server;//Server Information Class (this is not done)
Using WQ. text;//string Operation class (This is a static class, all static methods)
Using WQ. web;//Web page Common class (currently only complete the Image Watermark Class)

Compressed package Download: Wq.rar

First of all, one of the most important accessdata classes, when used very simple:

Using WQ. Data;
Public DataTable newstable;
protected void Page_Load (object sender, EventArgs e)
{
AccessData MyData = new AccessData ();
MyData. Open ();
mydata.commandtext= "SELECT * FROM [News]";
Newstable=mydata. Executedatatable ();//Returns a DataTable;
MyData. Close ();
}

Display on the. aspx page

<ul>
<%foreach (System.Data.DataRow R in Newstable.rows) {%>
<li><a href= "xxx.aspx?id=<%=r[" id ". ToString ()%> "><%=r[" title "]. ToString ()%></a></li>
<%}%>
</ul>

If you want to put the data in a GridView:

Gridview1.datasource=mydata. Executedatatable ();
Gridview1.databind ();

It should be noted that the above we do not see the driver of the database, because the driver is in the Web.config configuration file, so in the use of this class, please configure First.

<connectionStrings>
<add name= "connstring" connectionstring= "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=| Datadirectory|pub.mdb "providername=" System.Data.OleDb "/>
</connectionStrings>

If you have multiple Access databases, for example:

<connectionStrings>
<add name= "connstring" connectionstring= "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=| Datadirectory|pub.mdb "providername=" System.Data.OleDb "/>
<add name= "Connmac" connectionstring= "Provider=Microsoft.Jet.OLEDB.4.0;Data source=| Datadirectory|mac.mdb "providername=" System.Data.OleDb "/>
<add name= "Conncai" connectionstring= "Provider=Microsoft.Jet.OLEDB.4.0;Data source=| Datadirectory|cai.mdb "providername=" System.Data.OleDb "/>
</connectionStrings>

The name cannot be the same at the time of configuration, Accessdata.open () The default is to open the Name= "connstring" database, if you want to open another database (name= "Connmac"):

AccessData MyData = new AccessData ();
MyData. Webconfigconnectionname= "Connmac";
MyData. Open ();
....
MyData. Close ()//Shut down the database don't forget

If you don't or don't want to configure Web.config, you can also write the drive directly into the constructor:

String connstring= "Provider=Microsoft.Jet.OLEDB.4.0;Data source=" +server.mappath ("~/app_data/pub.mdb");
AccessData MyData = new AccessData (connstring);
MyData. Open ();
....
MyData. Close ();

If you are querying only one of the data, you can return directly to a ArrayList:

mydata.commandtext= "SELECT [Title],[content],[datetime] from [news] where id=3";
ArrayList Newslist=mydata. Executearraylist ()//Returns a ArrayList

When used, it is possible to use the lightest data directly:

<div>
<div><label> News title: <%=newslist[0]. ToString ()%></label></div>
<div> news content: <%=newslist[1]. ToString ()%></div>
<div> release date: <%=newslist[2]. ToString ()%></div>
</div>

There are other ways, I will not be one of the examples here:

MyData. ExecuteNonQuery ()//executes the current SQL statement and returns the number of rows affected
MyData. ExecuteReader ()//executes as a row SQL statement and generates a OleDbDataReader
MyData. ExecuteScalar ()//executes the row SQL statement and returns data from the first column of the row, ignoring other row data
Mydata.getrowscount (String tabelname),//Returns the Total row data of a table

Let's say, the paging property of this AccessData class Datapages,wq. Data has a separate page class to handle pagination:

Using WQ. Data;
Public DataPages newstable;
protected void Page_Load (object sender, EventArgs e)
{
AccessData MyData = new AccessData ();
MyData. Open ();
mydata.commandtext= "SELECT * FROM [News]";
Newstable=mydata. datapages;//returns a paging set object;
MyData. Close ();
newstable.pagesize=10;//10 lines per page
newstable.pageindex=3;//position the current page to 3 pages
}

The following is a pseudo URL configuration class that does not need to be instantiated and used (you must refer to Wq.dll in your project) just configure the configuration file web.config. First, add in the <configuration> node:

<configSections>
<section name= "Rewriterconfig" type= "WQ". Rewriter.rewriterconfigserializersectionhandler "/>
</configSections>

Remember this to add the front and then add or modify in <system.web>:

<add name= "Modulerewriter" type= "WQ". Rewriter.moduleurlrewriter "/>

Last configuration rewrite rule:

<configSections>
<section name= "Rewriterconfig" type= "WQ". Rewriter.rewriterconfigserializersectionhandler "/>
</configSections>
<RewriterConfig>
<Rules>
<!--pseudo URL rewrite configuration-->
<RewriterRule>
<lookfor>~/news/(\d{1,4}). aspx</lookfor>//pseudo Path
<sendto>~/nt_event.aspx?cid=$1</sendto>//Original Path
</RewriterRule>
<RewriterRule>
<lookfor>~/news/(\w{1,6})/(\w{1,6})/abc.aspx</lookfor>//pseudo path
<sendto><! [cdata[~/default.aspx?act=$1&key=$2]]></sendto> Original Path
</RewriterRule>
</Rules>
</RewriterConfig>

Such pseudo URLs are configured to complete and the artifacts can be used throughout the project, noting that. NET can only host. aspx files.

These classes of detailed properties and methods, in the use of the time will be prompted, can not use a lot of space to describe and explain all the examples, and what questions to me email or in the group discussed.

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.