Dim mrc As ADODB.Recordset Private Sub cmdQuery_Click() Dim txtsql As String Dim MsgText As String txtsql = "select * from student_Info" Set mrc = Executesql(txtsql,MsgText) Call viewData ’调用该函数 Set txtMoney.DataSource = mrc txtMoney.DataField = "cash" End Sub Private Sub Form_Load() Dim MsgText As String Dim txtsql As String txtsql = "select * from student_Info" Set mrc = Executesql(txtsql,MsgText) '得到student表,并显示出来 'select得到的临时表,游标指向尾记录,在Access中指向第一条 mrc.MoveFirst End Sub Private Sub viewData() txtStudentno.Text = mrc.Fields(1) txtstudentName.Text = mrc.Fields(2) ' 把临时表中当前记录赋给文本框 txtsex.Text = mrc.Fields(3) txtDepartment.Text = mrc.Fields(4) txtGrade.Text = mrc.Fields(5) txtClassno.Text = mrc.Fields(6) txtstatus.Text = mrc.Fields(10) txtcomment.Text = mrc.Fields(8) txtMoney.Text = mrc.Fields(9) End Sub
注:
文本框的DataField属性:
返回/设置一个值,将控件绑定到当前记录的一个字段。
DataSource属性:
设置一个数值,指出数据控件通过它将当前控件绑定到数据库。
原文链接:/vb/258516.html