SoFunction
Updated on 2025-04-14

ASP link database string summary


In addition, if it is a variable passed in by a query, it is as follows:

strau=("author")
strsql="select * from book where author='"&strau&"'"

If the query is a number, then:

intID=("id")
strsql="select * from book where select * from book where id='"&intID&"'".
However, character types must not be written in numeric format, so you need to pay attention.

2. Add records (Insert)
Syntax: Insert into table(field1,field2,......) Values (value1,value2,....)
Example: Add a record with the author "cancer" into the book table:
insert into book (bookno,author,bookname) values ('CF001','cancer','Cancer component-free upload program')
Similarly, if a variable is used, it is as follows:

strno=("bookno")
strau=("author")
strname=("bookname")
strsql="insert into book (bookno,author,bookname) values ('"&strno&"','"&strau&"','"&strname&"')"

3. Method of inserting data using Addnew of Recordset object:
grammar:


rs("field1").value=value1
rs("field2").value=value2
...


4. Modify the data record (Update)
Syntax: update table set field1=value1,field2=value2,...where fieldx=valueex
Example: update book set author='babycrazy' where bookno='CF001'
If you use variables, it is as follows:

strno=("bookno")
strau=("author")
strsql="update book set author='"&strau&"' where bookno='"&strno"'"

Update method of the object:
grammar:

rs("field1").value=value1
rs("field2").value=value2
...


Note: When using Syntax 3 and Syntax 5, be sure to pay attention to the consistency of the field type (especially the date type), otherwise the chance of error is very high.


example:

strno=("bookno")
strau=("author")
set adocon=("")
 "Driver={Microsoft Access Driver(*.mdb)};DBQ=" & _
=("/cancer/")
strsql="select * from book where bookno='"&strno&"'"
set rs=("")
 strsql,adconn,1,3
if not  then 'If there is this record
rs("author").value=strau

end if

set rs=nothing

set adocon=nothing

6. Delete a record (Delete)
Syntax: Delete where field=value
Example: Delete the record in the book table whose author is the cancer

delete book where author='cancer'

(Note: If there are multiple records with the author field value of the cancer in the book table, all records with the author as cancer will be deleted)

Okay, I have learned to use these operations. When you use asp to operate the database, there should be no problem.