Private Sub DBGrid1_RowColChange(LastRow As Variant, ByVal LastCol As Integer) If Val(LastRow) <> DBGrid1.Row Then Text1.Text = Data1.Recordset("要显示的字段名") End If End Sub
我认为你可以这样 你试试吧,好用的 记得要引用adoDim WithEvents adoPrimaryRS As Recordset '数据库连接对象 Private Sub Command1_Click() 'strsql 是你的查询语句 你可以order by 排序的字段 'strsql="select xh as 学号 from 表" 这里的学号就是你数据表中字段的标题 strsql="select 字段 from 表" Set Db = New Connection Db.CursorLocation = adUseClient '下面的连接数据字符串你要修改一下 Db.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\计划管理系统.mdb;Persist Security Info=False" Set adoPrimaryRS = New Recordset adoPrimaryRS.Open strsql, Db, adOpenStatic, adLockOptimistic Set DataGrid1.DataSource = adoPrimaryRS end sub 将数据显示出来以后 当点击某行时用text1.text=rs.fields("字段")
Text1.Text=rs.Fields("要显示的字段名")
If Val(LastRow) <> DBGrid1.Row Then
Text1.Text = Data1.Recordset("要显示的字段名")
End If
End Sub
你试试吧,好用的
记得要引用adoDim WithEvents adoPrimaryRS As Recordset '数据库连接对象
Private Sub Command1_Click()
'strsql 是你的查询语句 你可以order by 排序的字段
'strsql="select xh as 学号 from 表" 这里的学号就是你数据表中字段的标题
strsql="select 字段 from 表"
Set Db = New Connection
Db.CursorLocation = adUseClient
'下面的连接数据字符串你要修改一下
Db.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\计划管理系统.mdb;Persist Security Info=False"
Set adoPrimaryRS = New Recordset
adoPrimaryRS.Open strsql, Db, adOpenStatic, adLockOptimistic
Set DataGrid1.DataSource = adoPrimaryRS
end sub
将数据显示出来以后
当点击某行时用text1.text=rs.fields("字段")