select是SQL結構查詢語言命令之一。
1)SQL 語句,定義結構查詢語言 (SQL) 命令的表示式,例如 SELECT、UPDATE 或 DELETE,也可能包括像 WHERE 和 ORDER BY
這樣的子句。SQL 字串語句一般在查詢和 rdoResultset
物件中使用,但也可以用來建立或修改資料庫結構。
SQL 語句的語法與資料來源有關。
2)SELECT - SQL命令
句法:
SELECT [ALL | DISTINCT] [TOP nExpr [PERCENT]]
[Alias.] Select_Item [AS Column_Name]
[, [Alias.] Select_Item [AS Column_Name] ...]
FROM [FORCE]
[DatabaseName!]Table [[AS] Local_Alias]
[[INNER | LEFT [OUTER] | RIGHT [OUTER] | FULL [OUTER] JOIN
DatabaseName!]Table [[AS] Local_Alias]
[ON JoinCondition …]
[[INTO Destination]
| [TO FILE FileName [ADDITIVE] | TO PRINTER [PROMPT]
| TO SCREEN]]
[PREFERENCE PreferenceName]
[NOCONSOLE]
[PLAIN]
[NOWAIT]
[WHERE JoinCondition [AND JoinCondition ...]
[AND | OR FilterCondition [AND | OR FilterCondition ...]]]
[GROUP BY GroupColumn [, GroupColumn ...]]
[HAVING FilterCondition]
[UNION [ALL] SELECTCommand]
[ORDER BY Order_Item [ASC | DESC] [, Order_Item [ASC | DESC] ...]]
3)
SELECT - SQL命令例子:
下面的例子說明了如何使用SELECT的使用者定義的函式用法。
例子1
例子1 顯示所有企業在客戶的名稱(從一個表中的一個欄位)。
SELECT customer.company FROM customer
例子2
例子2 顯示兩個表中三個欄位的內容,並加入基於cust_id欄位的兩個表。它使用本地別名兩個表。
SELECT a.company, b.order_date, b.shipped_on FROM customer a, orders b WHERE a.cust_id = b.cust_id
例子3
例子3 僅顯示在指定領域唯一的資料記錄。
SELECT DISTINCT a.company, b.order_date, b.shipped_on FROM customer a, orders b WHERE a.cust_id = b.cust_id
例子4
例子4 顯示國家,郵編和公司按升序領域。
SELECT country, postalcode, company FROM customer ORDER BY country, postalcode, company
4)VB將上述例句作為字串賦值給ADO資料物件,或者ADO資料訪問控制元件屬性,進而完成資料查詢。
程式碼1:
Private Sub Command1_Click()
Dim cnn As New Connection
Dim rs As New Recordset
Dim sql As String
Dim ARR
cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\wdOld.mdb;Persist Security Info=False"
sql = "select 故障名稱 from guzhang_bm"
rs.Open sql, cnn
Combo1.Text = "故障名稱"
Do While Not rs.EOF
Combo1.AddItem rs("故障名稱")
rs.MoveNext "開啟表
Loop
rs.Close
cnn.Close
End Sub
程式碼2:
Private Sub Form_Load()
Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\Program Files\Microsoft Visual Studio\VB98\BIBLIO.MDB;Persist Security Info=False"
Adodc1.RecordSource = "select * from Authors"
Adodc1.Refresh
Debug.Print Adodc1.Recordset.Fields(2).Name
Set DataGrid1.DataSource = Adodc1
select是SQL結構查詢語言命令之一。
1)SQL 語句,定義結構查詢語言 (SQL) 命令的表示式,例如 SELECT、UPDATE 或 DELETE,也可能包括像 WHERE 和 ORDER BY
這樣的子句。SQL 字串語句一般在查詢和 rdoResultset
物件中使用,但也可以用來建立或修改資料庫結構。
SQL 語句的語法與資料來源有關。
2)SELECT - SQL命令
句法:
SELECT [ALL | DISTINCT] [TOP nExpr [PERCENT]]
[Alias.] Select_Item [AS Column_Name]
[, [Alias.] Select_Item [AS Column_Name] ...]
FROM [FORCE]
[DatabaseName!]Table [[AS] Local_Alias]
[[INNER | LEFT [OUTER] | RIGHT [OUTER] | FULL [OUTER] JOIN
DatabaseName!]Table [[AS] Local_Alias]
[ON JoinCondition …]
[[INTO Destination]
| [TO FILE FileName [ADDITIVE] | TO PRINTER [PROMPT]
| TO SCREEN]]
[PREFERENCE PreferenceName]
[NOCONSOLE]
[PLAIN]
[NOWAIT]
[WHERE JoinCondition [AND JoinCondition ...]
[AND | OR FilterCondition [AND | OR FilterCondition ...]]]
[GROUP BY GroupColumn [, GroupColumn ...]]
[HAVING FilterCondition]
[UNION [ALL] SELECTCommand]
[ORDER BY Order_Item [ASC | DESC] [, Order_Item [ASC | DESC] ...]]
3)
SELECT - SQL命令例子:
下面的例子說明了如何使用SELECT的使用者定義的函式用法。
例子1
例子1 顯示所有企業在客戶的名稱(從一個表中的一個欄位)。
SELECT customer.company FROM customer
例子2
例子2 顯示兩個表中三個欄位的內容,並加入基於cust_id欄位的兩個表。它使用本地別名兩個表。
SELECT a.company, b.order_date, b.shipped_on FROM customer a, orders b WHERE a.cust_id = b.cust_id
例子3
例子3 僅顯示在指定領域唯一的資料記錄。
SELECT DISTINCT a.company, b.order_date, b.shipped_on FROM customer a, orders b WHERE a.cust_id = b.cust_id
例子4
例子4 顯示國家,郵編和公司按升序領域。
SELECT country, postalcode, company FROM customer ORDER BY country, postalcode, company
4)VB將上述例句作為字串賦值給ADO資料物件,或者ADO資料訪問控制元件屬性,進而完成資料查詢。
程式碼1:
Private Sub Command1_Click()
Dim cnn As New Connection
Dim rs As New Recordset
Dim sql As String
Dim ARR
cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\wdOld.mdb;Persist Security Info=False"
sql = "select 故障名稱 from guzhang_bm"
rs.Open sql, cnn
Combo1.Text = "故障名稱"
Do While Not rs.EOF
Combo1.AddItem rs("故障名稱")
rs.MoveNext "開啟表
Loop
rs.Close
cnn.Close
End Sub
程式碼2:
Private Sub Form_Load()
Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\Program Files\Microsoft Visual Studio\VB98\BIBLIO.MDB;Persist Security Info=False"
Adodc1.RecordSource = "select * from Authors"
Adodc1.Refresh
Debug.Print Adodc1.Recordset.Fields(2).Name
Set DataGrid1.DataSource = Adodc1
End Sub