Graduation Summary: Learn to extrapolate, expand more functions

Source: Internet
Author: User
Tags filter cdata functions sql sql injection table name variable access

Graduation Summary: Learn to extrapolate you can save sometimes efficient, Itong!

Namespaces:

Socut.data

CData class

Implementation function: Read (DataSet method), insert, UPDATE, delete, statistic

Call Method:

Public CDATA Mydata=new CDATA ();

Actual operation:

1, read

Public DataSet Ds=new DataSet (); This dataset class has been provided by the Microsoft package

Ds=mydata.getdataset ("SELECT * from table WHERE condition", start line, number of rows, "virtual table name");

2, insert

Mydata.getexecutenonquery ("INSERT into table (column 1, column 2) VALUES (variable 1, variable 2)");

2, update

Mydata.getexecutenonquery ("UPDATE table set column 1 = variable A, column 2 = variable b WHERE condition");

3, delete

Mydata.getexecutenonquery ("DELETE table WHERE condition");

5, statistics

Mydata.getexecutescalar ("SELECT * from table WHERE condition", statistical type)

Statistical types are divided into two categories:

int integral type: 1

Double decimal point: 2 (Memory Method: If you know that double has "double" in the English word, then the type corresponding value can be associated with "2")

CReader class implementation function: Read (DataReader Reader Way)

Call Method:

public CReader Dr;

Actual operation:

Dr=new CReader ("SELECT * FROM table WHERE condition");

//

if (Dr. Read ())

{

Terminates the next row of reads immediately if the value of a particular condition exists

}//

while (Dr. Read)

{

Iterate through the values that match the criteria

}//

Call the value read out:

dr["column name"]

Close after use: Dr. Close ();

More extension Features

1, how to implement the search function?

A: Using GetDataSet, or creader, is possible, because it is simply a read of the contents of a database. The key is the use of SQL statements, which should be for select * FROM table name 1 WHERE column 1 like ' Search for keywords '

2, how to achieve the total number of articles reading statistics?

A: You need to add all the columns that meet the requirements and use the getexecutescalar statistic to do it, example: Double d1= (double) getexecutescalar ("Select SUM (column name to be counted) from Table Name 1 WHERE condition ", 2);

3. How do I develop a forum, or a mall?

A: The function of the forum is almost the same as the news system, you just add a reply function. Hint: A new column in the original news table, 0 on behalf of the main paste, greater than 0 of the number, the post is on behalf of the paste, the main sticker ID is xx. Shopping cart, in fact, is the use of session will be purchased content temporarily, the final checkout at one time insert the database.

4, in the development of the Forum, read the posts at the same time I also want to display the user's information, have to read two tables, how to do?

A: It can be implemented GetDataSet or CReader, because this is just a database read. The key is the use of SQL statements: SELECT * from news table, user table WHERE News table. Name of the person to be named = User table. User Registration Name

5, I want to let the latest article in the top, how to do?

A: It can be implemented GetDataSet or CReader, because this is just a database read. The key is the use of ASC (ascending) or desc (descending) in the SQL statement. Example: SELECT * FROM table name 1 WHERE condition ORDER by Time column DESC6, how to prevent hacker SQL injection? (Critical procedure: extremely high)

Answer: The most basic to filter the "'" symbol, so that hackers can avoid the construction of SQL statements. As in the 16th section of this news system, when the user logs in, the TextBox1.Text.Replace ("'", "") is executed first, and then the SQL statement executes. When you insert data, you also use replace filter.

7, to achieve a key switching function of the database, what should be paid attention to?

A: There are actually some differences between access and SQL Server SQL statements. For example, to delete a statement, in Access, you can use delete * from or delete from, and SQL Server can only use delete from. In addition, the default value properties of the original data are lost when the database data is switched. Therefore, to achieve a key switch to the database, pay attention to two points:

1, using a common SQL statement;
2, try to avoid using default values (such as automatic numbering and GUID encoding instead).



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.