日期:2014-05-16 浏览次数:20565 次
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属性:
设置一个数值,指出数据控件通过它将当前控件绑定到数据库。