VB,SQL相关问题

来源:百度知道 编辑:UC知道 时间:2024/06/08 06:36:33
在数据库的表1中,如何把某一字段的最大,最小和平均值查询出来并用datagrid显示,以及赋值给text控件?
我是查询某一字段的最大,最小和平均值,参考了一些资料,说可以用select max(字段1),min(字段1),avg(字段1) from 表1,但是我试过了,好像不行!

我用的是ADO连接SQL数据库
代码你可以这样写

Adodc1.ConnectionString = "Provider=SQLOLEDB.1;Password=2752;Persist Security Info=True;User ID=sa;Initial Catalog=sample;Data Source=JAMLEEPC"
Adodc1.RecordSource = "select 编号,姓名,年龄, 学历,年级,入学时间 from " & 人员表 & " order by '编号'"
Adodc1.Refresh
Form1.Show
If Adodc1.Recordset.RecordCount = 0 Then
MsgBox "无人员记录", vbOKOnly, "提示信息"
Else
Set DataGrid1.DataSource = Adodc1
End If

TEXT显示的代码这样写可以的
For j = 0 To 5
Text1(j).Text = Adodc1.Recordset.Fields(j)
Next j
End If

在Module写以下代码:
Public Function exesql(ByVal SQL As String) As ADODB.Recordset
cn.ConnectionString = "provider=Microsoft.jet.OLEDB.4.0;" & _
"Persist security info= False; Data source=" & App.Path & "\Daily.mdb"
cn.Open

rs.CursorLocation = adUseClient
rs.Open Trim$(