Database operations are frequently used. Including connections Code SQL commands and so on, and never deliberately remember them (I am not willing to remember this stuff), so I often look up books and turn them over when using them. Some of the less-used databases may not be able to be found smoothly, so I will summarize them here for your reference. (Personal skills are limited. If you have any defects, please let us know .)
<1>. Database Connection method:
1. Access database DSN-less connection method:
Set adocon = server. Createobject ("ADODB. Connection ")
Adoconn. Open "driver = {Microsoft Access Driver (*. mdb)}; DBQ = "&_
Server. mappath ("database path ")
2. Access ole db connection method:
Set adocon = server. Createobject ("ADODB. Connection ")
Adocon. Open "provider = Microsoft. Jet. oledb.4.0 ;"&_
"Data Source =" & server. mappath ("database path ")
3. SQL server connection method:
Set adocon = server. Createobject ("ADODB. recordset ")
Adocon. Open "driver = {SQL Server}; server = (local); uid = ***; Pwd = ***;"&_
"Database = database name ;"
4. SQL Server OLE DB connection method:
Set adocon = server. Createobject ("ADODB. Connection ")
Adocon. Open "provider = sqloledb.1; Data Source = ritant4 ;"&_
"User ID = ***; Password = ***;"&_
"In‑catalog = database name"
5. Oracle connection method:
Set adocon = server. Createobject ("ADODB. Connection ")
Adocon. Open "driver = {Microsoft ODBC for Oracle}; server = oraclesever. World; uid = admin; Pwd = pass ;"
6. Oracle ole db connection method:
Set adocon = server. Createobject ("ADODB. Connection ")
Adocon. Open "provider = oraoledb. Oracle; Data Source = dbname; user id = admin; Password = pass ;"
7. DBASE connection method:
Set adocon = server. Createobject ("ADODB. Connection ")
Adocon. Open "driver = {Microsoft DBASE Driver (*. DBF)}; driverid = 277; DBQ = ------------;"
8. MySQL connection method:
Set adocon = server. Createobject ("ADODB. Connection ")
Adocon. Open "driver = {MySQL}; database = yourdatabase; uid = username; Pwd = yourpassword; option = 16386 ;"
9. Visual FoxPro connection method:
Set adocon = server. Createobject ("ADODB. Connection ")
Adocon. Open "driver = {Microsoft Visual FoxPro driver}; sourcetype = dBc; sourcedb = *. dBc; exclusive = no ;"
10. Ms text connection method:
Set adocon = server. Createobject ("ADODB. Connection ")
Adocon. Open "driver = {Microsoft text Driver (*. txt; *. CSV)}; DBQ = -----;"&_
"Extensions = ASC, CSV, tab, txt; persist securityinfo = false ;"
11. Ms text ole db connection method:
Set adocon = server. Createobject ("ADODB. Connection ")
Adocon. Open "provider = microsof. Jet. oledb.4.0; Data Source = your_path ;"&_
"Extended properties 'text; FMt = delimited '"
<2>. Four Common SQL commands:
1. query data records (select)
Syntax: Select field serial from table where field = content
Example: If you want to find all the records whose author is "cancer" from the book table, the SQL statement is as follows:
Select * from book where author = 'cancer'
"*" Is to retrieve all the fields in the book table. If the queried field value is a number, then the "content" after the query does not need to be enclosed by single quotation marks,
If it is a date, it is included in access (#), while in SQL Server,
For example:
Select * from book where id = 1
Select * from book where pub_date = #2002-1-7 # (ACCESS)
Select * from book where pub_date = '2014-1-7 '(SQL Server)
Tip:
The date function to_date is not a standard SQL document and is not applicable to all databases. Therefore, you should refer to the specific database syntax when using it.