Access to the database (4)
Hello, I am Wuhan Sunwen, some days ago to tell you some of the basic syntax of SQL, and then for several days without the following. This is because the school these days are having a sports meeting, I also ran 800 meters, although no place, but also tired half to death, after all, I have to fight to the fullest. Originally I have no strength to write down today, but think of my Learning ASP process, I began to play the spirit, open the computer, wrote up. (It's a very professional spirit!) )
Today I would like to tell you a little bit of SQL knowledge, and then back to the ASP.
B. Inserting data
This is of course also a very important content, look at the following introduction bar:
The 1.column_list parameter specifies which columns the INSERT statement inserts data into
The 2.VALUES clause provides data for the column specified by the column_list parameter in the newly inserted row, either as a constant or an expression, or by using the Defalt keyword description to insert its default value into the column
3.default values Note Inserts the default values into all columns in the table
4. When selecting select_statement, insert statement Inserts the result returned by the select_statement clause into the specified table
5.table_souces the table or view in which you want to insert data
Example: when inserting data into a table using a numeric list, the column data in the VALUES clause is ordered to be in exactly the same order as the definition in the table
Insert TB values (' YPF ', ', ', ' 99999 ')
In this example TB represents the name of a table, and values indicate the data to be inserted into columns in the table in the same order as in the actual table
Example two: The order can also be specified:
Insert TB (Phone,name) VALUES (' 899999 ', ' user ')
In this example TB (Phone,name) represents the phone and name columns in TB tables, and values (' 899999 ', ' user ') specify what is inserted into the two columns. The column corresponds to the data to be inserted one by one. In addition, we can replace the variable to the data, such as: Values (a,b), a,b is two variables, but remember that its variable type must be consistent with the type of the column, or you will produce an error. We can also use default for data, which is used to indicate inserting a default value into this column. such as: Insert TB (phone,name) VALUES (DEFAULT ', ' user ')
OK, let's start with ASP again!
Through the course above we already know how to do something with a database. But we know that we are now in the use of VBScript to write ASP, and VB in the form of the character variable is a= "ABCD", that is, we refer to a character data, is actually referring to "ABCD." Say a sentence like this: Insert TB values (A, ' poi ') where a represents "ABCD", and this statement is actually insert TB values ("ABCD", ' poi '), find the problem! In our last lesson, we talked about the reference to character variables in SQL that should be delimited by single quotes, and we used double quotes in the previous statement. This is bound to cause problems. So, when we want to put a form in a page, including a text, we use another ASP to refer to the content of this text, and to write the contents of this text to the database, with an INSERT statement will cause problems, It's more difficult to turn double quotes into single quotes. So, today I'm going to introduce you to another way to insert data into a database by using the AddNew method of the Recordset.
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