ASP quotes, How to Write SQL statements in ASP

Source: Internet
Author: User
Tags first string
Document directory
  • (1) double quotation marks
  • (2) single quotes
  • Note:
  • (3) join operators &
  • Note:
  • (4) A common mistake: Writing string variables to string constants
  • 2.1 Insert text and remarks fields into SQL strings
  • 2.2 Insert numeric and Boolean field values into SQL strings
  • 2.3 Insert a date field value into an SQL string
  • 2.4 Comprehensive example
  • 2.5 tips
  • 3.1 database modification method
  • 3.2 program modification method
  • Note:
  • (1) Database File Permission Error
  • (2) spelling error
  • (3) The field name or table name is invalid.
  • (4) Missing required fields
  • (5) Missing quotation marks on both sides of text or remarks fields
  • (6) An empty string ''' is added incorrectly ''''
  • (7) space is missing
  • (8) double quotation marks are missing.
  • (9) The concatenation operator is missing.
  • (1) check whether the SQL string is incorrect.
  • (2) carefully check the SQL string
  • (3) output the SQL string to the page
  • (4) copy the SQL string to the access query for execution.

Learning ASP. in the process of net, many students feel difficult when writing SQL strings, always encounter various errors, and are very difficult to grasp the double quotation marks, single quotation marks and join operators. This article describes how to write correct SQL strings from the beginning and provides a more effective debugging method.

1 double quotation marks, single quotation marks, and join operators &

First, declare that the symbols here are symbols in English, or symbols used in syntax.

When writing SQL statements, the most common confusion is the understanding of double quotation marks, single quotation marks, and join operators. Let's start with the basics.

(1) double quotation marks

In ASP, double quotation marks must be added to both sides when a String constant is used to indicate a string. Below are all string constants:

"Abcdefg"

"Great Motherland"

"101"

"2003-10-5"

You may think that 101 is a number and-10-5 is a date. However, if double quotation marks are added on both sides, it is a string regardless of whether the content is a number, an English letter, or a Chinese character.

(2) single quotes

Some may think about it. You can use double quotation marks to indicate that it is a string, but if double quotation marks are used in the middle of the string, then this may happen:

"AB" CDE "FG"

This will obviously lead to misunderstanding. What exactly is the first double quotation mark matching the second double quotation mark? According to ASP, when double quotation marks are nested, you can change the double quotation marks in the inner layer to single quotation marks or change two consecutive double quotation marks "". According to this rule, the above string should be rewritten to the following form:

"AB 'cde' FG"

"AB" "CDE" "FG"

Note:

1. In most cases, when quotation marks are nested, you can change the inner quotation marks to single quotation marks, that is, the first form.

2. In special cases, the second form is required. Because there are some differences between the two, when using them, the middle of the 1st form is a single quotation mark, while the middle of the second form is actually a double quotation mark, you can use response. write statements output them to the page for comparison.

However, it should be noted that the nested quotation marks here are all for characters in the English state. If there are Chinese quotation marks in the middle of the string, they do not need to be replaced. The following strings are valid:

"Long live the great motherland"

"Great" Long live the motherland"

This also reminds us that when processing the data submitted by the customer, if the customer inputs all Chinese characters, then whatever the input, it can be treated as a string. However, if the customer inputs English, the string nesting may occur.

(3) join operators &

When using strings, we often need to connect two or more strings into a large string. In this case, we need to use the concatenation operator & (at this time, we can also use +, but generally use &), as follows:

"ABCD" & "EFG"

"ABCD" & "EFG" & "hijk"

For the above two expressions, the result of the join operation is as follows:

"Abcdefg"

"Abcdefghijk"

Let's take a look at the connection operation principle. Taking the first expression as an example, it actually removes the content ABCD between two double quotes, then, extract the content EFG from the second string and link them to abcdefg. Of course, their results are still string constants. Therefore, double quotation marks must be added on both sides to indicate that the String constant is in the middle, so it becomes the final "abcdefg ".

The second expression is essentially the same as the above, except that the first string and the second string are first connected into a string, then they are connected to the third string to form the final string.

Note:

1. Some students come up with a formal understanding method, which is to erase the "&" in the middle and connect them together. The results are the same, but the actual principle is as follows.

2. For "ABCD" & "EFG", remove the spaces on both sides in ASP to become "ABCD" & "EFG ". However, it is recommended to add spaces so that the program will be clearer.

3. Sometimes, expressions may have more join operators. The operation procedure is the same, from left to right.

The above example is relatively simple. If there are single quotation marks in the middle, it may become more complicated. However, you only need to remember that, no matter whether there are single quotes, the content between the double quotes on both sides of a string is the content of this string, and the content must be obtained during the connection, you only need to use single quotes as common characters. Example:

"AB 'cd' EFG" & "Hi 'jk 'lmn"

After the connection operation is executed, the result is as follows:

"AB 'cd' efghi'jk 'lmn"

As for the specific principle, just follow the above explanation. Connect the content 'cd' EFG In the first string and the content 'jk 'lmn In the second string to the AB 'cd' efghi 'jk 'lmn, double quotation marks are added on both sides to indicate that this is a String constant "AB 'cd' efghi'jk 'lmn ".

Well, I believe that you are clear about the concepts of double quotation marks, single quotation marks, and join operators. Some other students may come up with the above example ("ABCD" & "EFG ") it seems that it doesn't make much sense. This formula is directly written as "abcdefg". Why bother dividing it into two parts and adding a connector in the middle?

This idea is actually correct. In actual use, although we sometimes use & to connect two string constants, it is more often to connect a String constant and a string variable, or connect two string variables together. As follows:

"AB 'cd' EFG" & strtemp

You can note that in the above expression, the first is a String constant, and the second is a string variable. So how do they perform join operations? It is actually very simple:

If strtemp = "Hi 'jk 'lmn", then it is substituted into the above expression, then the above expression becomes

"AB 'cd' EFG" & "Hi 'jk 'lmn"

The operation principle is the same as described above. The final result is "AB 'cd' efghi 'jk 'lmn"

Others prefer to write it like this:

Strsql = "AB 'cd' EFG"

Strsql = strsql & strtemp

These two statements are the same as the above results after execution. The process is: Save "AB 'cd' EFG" in the first sentence to the variable strsql, extract the string from the variable in the second sentence, and then connect it with the string variable strtemp, save it to the variable strsql. If strtemp = "Hi 'jk 'lmn", the content in the variable strsql is "AB 'cd' efghi' JK 'lmn" after execution ".

(4) A common mistake: Writing string variables to string constants

A common mistake is to write the string variable directly to the String constant. For example, some of the above expressions are written

"AB 'cd' efgstrtemp"

He thinks this is to connect the String constant "AB 'cd' EFG" AND THE STRING variable strtemp. However, who else can see that strtemp is a string variable besides him?

In this incorrect writing method, the strtemp character is essentially different from the AB 'cd' EFG character. The system will not regard it as a string variable, but will only regard them as part of this large string. Or, This Is A String constant with the content of AB 'cd' efgstrtemp.

Therefore, you must remember that string variables cannot be directly written into string constants. When you want to connect a String constant with a string variable, use & (or +) to connect them together. For example:

"AB 'cd' EFG" & strtemp

Of course, the same is true if you want to connect two string variables, for example:

Strtemp1 & strtemp2

Also, several string constants and several string variables are sometimes connected together, such:

"AB 'cd' EFG" & strtemp & "Hi 'jk 'lmn"

Their operation principles and procedures are the same. The content of the string variable is substituted into the expression and the join operation is executed.

2. Write the correct SQL string

After a deep understanding of the above section, you can easily write SQL strings. In essence, SQL strings are common strings. Whether using string constants or string variables, you must connect them to a string that meets certain format requirements.

First of all, it should be emphasized that the SQL language has the following rules:

1. quotation marks must be placed on both sides of the field values corresponding to text and remarks fields.

2. Do not add any numbers, automatic numbers, or boolean values.

3. Add the # sign on both sides of the Child segment value corresponding to the date field. Use quotation marks instead in the SQL database.

4. You do not need to add the automatic number field yourself. The database will automatically add the field.

 

The following is an example of how to explain in advance that the following statements mainly use insert statements. In fact, the statements such as select, update, and delete are similar:

Assume that there is a database with the following data table users, which contains the following fields. All fields are set by default:

Field 1 ID is automatically numbered (This field does not need to be inserted, and the system automatically inserts it)

Field 2 username text type (that is, string type) (user name)

Field 3 age numeric type (AGE)

Field 4: Birthday (birthday)

Field 5 marry Boolean (married or not, true for marriage, false for not married)

Field 6 intro remarks (Overview)

2.1 Insert text and remarks field values in an SQL string (1) the simplest SQL string

Let's look at a simple SQL statement.

Insert into users (username) values ("John ")

Let's take a look. This is a standard SQL statement. Because username is a text field, double quotation marks must be added on both sides of the field value to indicate that John is a string.

The preceding SQL statement can be executed directly in the access query. However, in ASP programs, SQL statements are processed as strings, so we usually write

Strsql = "insert into users (username) values ('John ')"

In this case, the double quotation marks indicate a string in the middle. The single quotation marks on both sides of the King are nested because of quotation marks, so the inner quotation marks are changed to single quotation marks.

(2) Use string variables in SQL strings

When inserting a record, because "John" is usually obtained from a form, such as request. Form ("username"), you can also save it to a string variable myusername.

As mentioned in section 1st above, a string variable cannot be directly written to a String constant and must be connected together with a String constant. Therefore, the above example should be changed to the following form:

Strsql = "insert into users (username) values ('" & myusername &"')"

Some people are confused at this time. Why are there single quotation marks, double quotation marks, and connection operators? In fact, it is not complicated to recall the content described in the previous section.

In the expression on the right of the equal sign of this statement, it actually contains the following three parts: Two string constants and a string variable, which are connected together by the concatenation operator:

The first part of the String constant: "insert into users (username) values ('"

Part 2 string variable: myusername

Part 3 String constant :"')"

Which of the following is confusing: Why is the first part followed by a single quotation mark and a double quotation mark? Why does the third part start with a double quotation mark and a single quotation mark. In fact, for the first part, the double quotation marks on both sides indicate that the content in the center is a String constant. The single quotation marks are the same as other characters, but only the content of this string constant. Similarly, for the third part, the double quotation marks on both sides indicate that this is a String constant, and the single quotation marks and parentheses in the middle are its contents.

After understanding the composition of each part, some people may ask, I now know that this is a String constant connecting a string variable, and then connecting a String constant, I also know what is going on with single quotes and double quotes. But why do you want to write it like this? Why can't I write it like this.

In fact, from the perspective of our final goal, if the username (username field) entered by the user is "Xiao Wang", what we need at last is the following SQL string.

Strsql = "insert into users (username) values ('John ')"

Because the customer entered "Xiao Wang", the string variable myusername = "Xiao Wang" is substituted into the following expression:

Strsql = "insert into users (username) values ('" & myusername &"')"

It becomes

Strsql = "insert into users (username) values ('" & "John "&"')"

Execute two join operators in sequence and connect the three parts on the right to a string. The final result is as follows.

Strsql = "insert into users (username) values ('John ')"

We can see that this is the final SQL string we need. Now you can see clearly that the single quotation marks in the first part and the single quotation marks in the third part are the single quotation marks on both sides of the king, indicating that the King is a string.

(3) Use two string variables

In the preceding example, only one field is relatively simple. The following is an example of two fields. Assume that you want to insert two Field Values: username and intro (the intro field is in the remarks type, and the field values must be enclosed in quotation marks ).

Strsql = "insert into users (username, intro) values ('" & myusername & "', '" & myintro &> "')"

In this expression, both myusername and myintro are string variables, respectively saving the user name and user profile information. Analyze this expression now.

The right side of the equal sign is actually composed of the following five parts:

The first part of the String constant: "insert into users (username, intro) values ('"

Part 2 string variable: myusername

The third part is the string constant :"','"

Part 4 string variable: myintro

Part 5 String constant :"')"

Now let's take the string variable into consideration. For example, if myusername = "" and myintro = "", it becomes

Strsql = "insert into users (username, intro) values ('" & "" & "', '" & ""&"')"

Run the following four join operators in sequence:

Strsql = "insert into users (username, intro) values ('little king', 'good kid ')"

As you can see, this is a correct SQL string, because the two field values must be enclosed in quotation marks, so the original String constant contains several single quotes. The single quotation marks at the beginning of the first part and the third part are on both sides of the king, and the single quotation marks at the end of the third and fifth parts are a good child on both sides.

If you add more sub-segment values, and so on.

2.2 Insert numeric and Boolean field values into SQL strings

As mentioned above, in SQL strings, there is no need to add either numeric or Boolean field values.

(1) Insert a numeric field

If a record of 12 is inserted, the final SQL string should be as follows:

Strsql = "insert into users (AGE) values (12 )"

If the current age is a variable myage, it should be:

Strsql = "insert into users (AGE) values (" & myage &")"

Here, the right side of the equal sign is also three parts, respectively:

The first part of the String constant: "insert into users (AGE) values ("

Part 2 numeric variable: myage

Part 3 String constant :")"

Note that the numeric variable myage is automatically converted to a string in this expression. If myage = 12, it is actually converted to "12 ".

Strsql = "insert into users (AGE) values (" & "12 "&")"

Continuing to execute the join operator becomes the final result we need as follows.

Strsql = "insert into users (AGE) values (12 )"

(2) Insert a Boolean Field

The interpretation of the boolean type is the same as above, except that it only has two values: true and false, for example:

Strsql = "insert into users (marry) values (true )"

If you change to a Boolean variable mymarry

Strsql = "insert into users (marry) values (" & mymarry & ")"

2.3 Insert a date field value into an SQL string

The date type is similar to the text type, but you need to replace the single marker with the # marker. (However, you can use a single marker in the ACCESS database)

Strsql = "insert into users (birthday) values (#2005-3-1 #)"

If you replace it with the date variable mydate, it should be as follows:

Strsql = "insert into users (birthday) values (#" & mydate & "#)"

Note that the date variable mydate is automatically converted into a string, for example, after mydate = #2005-3-1 # is substituted into the string:

Strsql = "insert into users (birthday) values (#" & "2005-3-1" & "#)"

Run the join operator. The result is as follows:

Strsql = "insert into users (birthday) values (#2005-3-1 #)"

Pay special attention to the following two points:

(1) Many people often use the date () or now () functions here. You only need to regard it as a variable. For example:

Strsql = "insert into users (birthday) values (#" & date () & "#)"

(2) In the SQL database, # cannot be used here, and single quotation marks are also used, just like a text field value.

2.4 Comprehensive example

In the above example, we have inserted several fields with values, and many fields are inserted at the next time.

Strsql = "insert into users (username, intro, age, submit_date, marry) values ('" & myusername & "', '" & myintro &"', "& myage &", # "& mysubmit_date &" #, "& mymarry &")"

Assume that myusername = "", myintro = "", myage = 20, mysubmit_date = #2004-4-1 #, and mymarry = false are substituted into it, and the result is:

Strsql = "insert into users (username, intro, age, submit_date, marry) values ('" & "John
"&" ',' "&" "&" ', "&" 20 "&", # "&" 2004-4-1 "&"#, "&" true "&")"

Note that the values of date and numeric variables are automatically converted to strings. Perform the join operation in sequence and the result is:

Strsql = "insert into users (username, intro, age, submit_date, marry) values ('little king', 'good> Kid', 20, #2004-4-1 #, true )"

This is exactly the correct SQL string we need.

2.5 tips

The following is a tips for writing SQL strings. Replace the following statement with a variable:

Strsql = "insert into users (username) values ('zhanghong ')"

Step 1: First erase Zhang Hong and add two quotation marks in the original position

Strsql = "insert into users (username) values ('" "')"

Step 2: Add two connectors in the middle &

Strsql = "insert into users (username) values ('" & "')"

Step 3: Write the variable between two connectors

Strsql = "insert into users (username) values ('" & thename & "')"

You can refer to it, but you must understand the fundamental principles mentioned above.

3. How to add incomplete information to the database

When the customer fills in the form content, if the customer fills in all the content, then add all the Field Values in sequence according to the comprehensive example in section 2.4. However, in actual development, the customer should be allowed to omit some content. Otherwise, if there are too many projects, the customer may enter something crazy.

If we allow the customer to omit the personal profile, we will still use the string given in section 2.4:

Strsql = "insert into users (username, intro, age, submit_date, marry) values ('" & myusername & "', '" & myintro &"', "& myage &", # "& mysubmit_date &" #, "& mymarry &")"

The following variable values are available: myusername = "", myintro = "", myage = 20, mysubmit_date = #2004-4-1 #, and mymarry = false. Myintro = "" is an empty string, that is, a string with a length of 0.

The result is as follows:

Strsql = "insert into users (username, intro, age, submit_date, marry) values ('John ','', 20, #2004-4-1 #, true )"

Take a closer look at this expression. The field value corresponding to the intro field is changed to an empty string '', while the access database does not allow the insertion of null strings by default, therefore, an error occurs when you execute this statement.

So what should we do? Two Methods: one is to modify the database so that this field can be input with null strings; the other is to modify the program and delete this field from the insert statement, it is not allowed to appear in the SQL string.

The following explains in sequence:

3.1 database modification method

Open the database, go to the users table design interface, select the field intro, and select "yes" in the "allow empty strings" column below. After the database is modified, the program does not need to be modified.

3.2 program modification method

Modifying a database is simple, but sometimes it is not convenient to modify the database, so you can only modify the program. If the customer has entered the description, the intro field will appear in the insert statement. If the customer has not entered the description, the intro field will not appear in the insert statement. It is easy to say, because I don't know whether the customer will fill it out, so it is very difficult to write it down.

The following is an inappropriate example. If there are five couples, they are now arranged in the same queue below.

Husband 1 husband 2 husband 3 husband 4 Husband 5 wife 1 wife 2 Wife 3 Wife 4 wife 5

If the five couples are in the queue, it is easy. But what should we do if 5th couples may not come? We can use the following method to queue our husband and wife separately. First, we should arrange the first four couples separately, as shown below:

Husband 1, husband 2, husband 3, and 4

Wife 1 wife 2 Wife 3 Wife 4

Then, if 5th couples come, let them stand at the end of both teams. Finally, combine the two teams into one, as shown below:

Husband 1 husband 2 husband 3 wife 1 wife 2 Wife 3 ..

In this example, the intro field may or may not appear. Therefore, we can split the insert statement into the first and second parts. The first part is the field list and the last part is the field value list. If you enter a personal profile, add the intro field in the previous section and the field value in the later section. Otherwise, it will not be added. The code for writing an insert statement is as follows:

'Five variables are defined below to get the values in the form.

Dim username, age, birthday, marry, intro as string

Username = request. Form ("username ")

Age = request. Form ("Age ")

Birthday = request. Form ("Birthday ")

Marry = request. Form ("marry ")

Intro = request. Form ("Intro ")

'Organize the insert statement in the following two sections:

Dim sqla, sqlb, strsql as string

Sqla = "insert into users (username, age, birthday, marry"

Sqlb = "values ('" & username & "'," & age & ", #" & birthday & "#," & marry

If intro <> "" then

Sqla = sqla & ", Intro"

Sqlb = sqlb & ", '" & intro &"'"

End if

'Finally, combine the two parts into a complete insert statement.

Strsql = sqla & ")" & sqlb &")"

Note:

① The variable value is obtained as a string variable.

② The single quotation marks and double quotation marks in the preceding statements are the same as those in the previous sections. You can change various situations and substitute the variable value to view the final result.

③ If the customer does not enter the description, the final result is similar:

 

Strsql = "insert into users (username, age, submit_date, marry) values ('John ', 20, #2005-3-1 #, true )"

If the customer only fills in the description, the final result is similar:

Strsql = "insert into users (username, intro, age, submit_date, marry) values ('little king', 'good Kid', 20, #2005-3-1 #, true )"

And so on.

④ If it is difficult to determine what the final result is, you can add it under the strsql =... statement

Response. Write strsql

Response. End

In this way, the final result is output on the screen.

⑤ If there are more than one field, you can omit it, and so on. The most important thing is that the final connected SQL string is a standard and correct SQL string. >

4. Common Errors

In the debugging process, various errors often occur, similar to the following:

(1) Database File Permission Error

This error often prompts "an updatable query is required ". To be accurate, these errors are irrelevant to SQL strings. You need to set the database file permissions correctly.

(2) spelling error

This is also a common mistake. It is a spelling mistake. First, be careful. Second, you can use the methods in section 4 to debug and find errors.

(3) The field name or table name is invalid.

There are some reserved words in the system, such as user and date, which cannot be used for field names or table names.

In addition, do not use numbers as the names of tables or fields, such as 111 and 222. Although it can be used in access, an error may occur in SQL. It is best to use letters for the first letter.

If you must use it, you can also add brackets to the SQL strings used, for example:

Strsql = "insert into [users] ([username]) values ('zhanghong ')"

Strsql = "insert into [users] ([11111111]) values ('zhanghong ')"

(4) Missing required fields

If you specify a required field and the field is missing in SQL, an error will occur. For example, if username is the primary key, this field cannot be omitted. An error occurs in the following SQL string:

Strsql = "insert into users (age, intro) values (12, 'good kid ')"

(5) Missing quotation marks on both sides of text or remarks fields

Take a closer look at the following strings, with four single quotes missing:

Strsql = "insert into users (username, intro) values (" & myusername & "," & myintro & ")>"

The result may be as follows:

Strsql = "insert into users (username, intro) values (John, good boy )"

An error occurs because quotation marks are missing on both sides of the text field value.

The following example is also incorrect:

Strsql = "select * from users where username =" & myusername

Of course there are many similar errors, such as missing # on both sides of the date field and quotation marks on both sides of the number.

(6) An empty string ''' is added incorrectly ''''

If the database or program is not processed according to the method 3 and a form item is omitted, the following error may occur:

Strsql = "insert into users (username, intro, age, submit_date, marry) values ('John ','', 20, #2004-4-1 #, true )"

The value of intro is an empty string''

(7) space is missing

Different items in the SQL string are generally separated by spaces, some of which can be omitted, and some cannot be ignored. Let's take a closer look at the two statements below and think about whether there are any errors?

Strsql = "select * from users"

Strsql = strsql & "where username = '" & myusername &"'"

These two statements are connected to a complete SQL string after execution. The results are as follows:

Strsql = "select * From userswhere username = '" & myusername &"'"

As you can see, there is a space missing between users and where, so when they are connected together, errors will naturally occur. Therefore, if you want to combine strings using multiple such statements, you must pay attention to this problem. Leave a space before the WHERE clause in the second sentence, as shown below:

Strsql = "select * from users"

Strsql = strsql & "where username = '" & myusername &"'"

(8) double quotation marks are missing.

Such errors should also be spelling errors, as shown below:

Strsql = "insert into users (username, intro) values ('& myusername &"', '"& myintro &"'> )"

Take a closer look, values ('is missing a double quotation mark. In this way, we do not know which strings are constants.

(9) The concatenation operator is missing.

Take a closer look at the following. One before myusername is missing &.

Strsql = "insert into users (username, intro) values ('" myusername & "', '" & myintro &"')"

5. debugging method

Some people may say that the common errors mentioned above do occur frequently and I know it, but it is difficult to find out. Here we will> tell you how to debug them. The specific steps are as follows:

(1) check whether the SQL string is incorrect.

There are many types of errors, which may be due to many reasons, not necessarily to SQL strings. This is determined based on the error message.

In addition, it should be noted that, for the reason of the SQL string, the error does not necessarily occur in strsql =..., but in db. Execute (strsql.

(2) carefully check the SQL string

If the cause of the SQL string is true, check carefully from the following aspects:

1. Are there obvious spelling mistakes?

2. Are there obvious situations where double quotation marks, &, and spaces are missing?

3. are invalid field names used?

4. Are quotation marks missing on both sides of a text field value?

5. is an empty string illegal?

 

(3) output the SQL string to the page

If you still cannot see the error, you can go to strsql = .. after temporarily adding the following statement, the program will be interrupted and the SQL string will be output to the page. You can view the final result of the SQL string more carefully:

Strsql = "insert into users (username, intro, age, submit_date, marry) values ('" & myusername & "', '" & myintro &"', "& myage &", # "& mysubmit_date &" #, "& mymarry &")"

Response. Write (strsql)

Response. End

DB. Execute (strsql)

This output is the final SQL string, so it is easier to see the error. Especially for errors such as empty strings and spaces.

Of course, this method targets SQL strings that can be output. That is to say, although the SQL string cannot be correctly executed, it is still a correct string, but it is a string that does not meet the SQL requirements. If quotation marks and join operators are missing, this step cannot be correctly executed. That is, strings cannot be output at all.

(4) copy the SQL string to the access query for execution.

If you view the SQL string on the page in step (3), you still cannot see the error. Then you can open the ACCESS database, add a query in it, and copy the SQL string from the page to execute the query. This gives you a clear error message. The procedure is as follows:

Select the query button on the left side of the Access main window to display the dialog box. In this case, you do not need to add a table by yourself. Click Close and select View> SQL view in the main window, the SQL view dialog box 5-3 is displayed. Click Save. The name is select1. In Figure 5-3, click Run to display the query result immediately.

If the table or field name is incorrect, a dialog box is displayed immediately. If there are other errors, a message is displayed.

If everything is correct, it will be executed correctly. However, it should be noted that access is slightly different from ASP in extremely few cases. It can be used in access, but it cannot be used in ASP.

6. SQL Server database description

The above is for access databases. If you change to a SQL database, pay attention to the following two points:

(1) do not use the # sign on both sides of the date field value. Use single quotation marks.

(2) copy the SQL database to the query analyzer for execution.

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.