连接数据库就不写了 Set rst = Glo.Conn.Execute("select 预交金额 from 新卡用表 where 学号='"&text1.text&"'") text2.text=rst!预交金额
要引用ADO,rs和cn自己去定义: Private Sub Text1_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then rs.Open "select 预交金额 from 新卡用表 where 学号='" & Text1.Text & "'", cn, adOpenKeyset, adLockOptimistic If Not rs.EOF Then Text2.Text = rs!预交金额 End If End If End Sub
faysky2()朋友: 您好!您多次回答我的问题,一再的帮助我,我先给您鞠个躬,在这里再次道谢。 您给我的这些: Private Sub Text1_KeyPress(KeyAscii As Integer) Dim cn As New ADODB.Connection, rs As New ADODB.Recordset If KeyAscii = 13 Then rs.Open "select 预交金额 from 新卡总表 where 学号='" & Text4.Text & "'", cn, adOpenKeyset, adLockOptimistic If Not rs.EOF Then Text1.Text = rs!预交金额 End If End If End Sub 我按照您给的写了上去,稍微改了一下文本框的名称,当我把焦点移到text1时,我按回车键,出来一个信息提示:实时错误‘3709’,连接无法用于执行操作,在此上下文中它可能已被关闭或无效。 然后当我调试的时候,错语句总是显示『rs.Open "select 预交金额 from 新卡用表 where 学号='" & Text4.Text & "'", cn, adOpenKeyset, adLockOptimistic』这句话,请问,是那里出了问题呢?
Set rst = Glo.Conn.Execute("select 预交金额 from 新卡用表 where 学号='"&text1.text&"'")
text2.text=rst!预交金额
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
rs.Open "select 预交金额 from 新卡用表 where 学号='" & Text1.Text & "'", cn, adOpenKeyset, adLockOptimistic
If Not rs.EOF Then
Text2.Text = rs!预交金额
End If
End If
End Sub
您好!您多次回答我的问题,一再的帮助我,我先给您鞠个躬,在这里再次道谢。
您给我的这些:
Private Sub Text1_KeyPress(KeyAscii As Integer)
Dim cn As New ADODB.Connection, rs As New ADODB.Recordset
If KeyAscii = 13 Then
rs.Open "select 预交金额 from 新卡总表 where 学号='" & Text4.Text & "'", cn, adOpenKeyset, adLockOptimistic
If Not rs.EOF Then
Text1.Text = rs!预交金额
End If
End If
End Sub
我按照您给的写了上去,稍微改了一下文本框的名称,当我把焦点移到text1时,我按回车键,出来一个信息提示:实时错误‘3709’,连接无法用于执行操作,在此上下文中它可能已被关闭或无效。
然后当我调试的时候,错语句总是显示『rs.Open "select 预交金额 from 新卡用表 where 学号='" & Text4.Text & "'", cn, adOpenKeyset, adLockOptimistic』这句话,请问,是那里出了问题呢?
先要cn.open......