急求,如何从已经和VB链接好的access数据库里读取一列数据中最大的数据,并把这个数据放在text里显示

2024年11月20日 16:32
有1个网友回答
网友(1):

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim cstring As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\db.mdb"
Dim con As New OleDb.OleDbConnection(cstring)

Dim sql As String = "select max(字段名) from 表名"
con.Open()
Dim cmd As New OleDb.OleDbCommand(sql, con)
Dim myreader As OleDbDataReader = cmd.ExecuteReader
myreader.Read
TextBox1.Text = myreader(0)
con.Close()

End Sub