我依照VB书本上的一个简单的学生成绩管理程序代码,照着样子做出来,运行后,发现在文本框中输入了学号、姓名等,文本框里的数据全都消失了,请问怎么解决啊!急

解决方案 »

  1.   

    我把代码贴上来了,请指教!
    Private Sub Adodc1_MoveComplete(ByVal adReason As ADODB.EventReasonEnum, ByVal pError As ADODB.Error, adStatus As ADODB.EventStatusEnum, ByVal pRecordset As ADODB.Recordset)
    Adodc1.Caption = "记录:" & (Adodc1.Recordset.AbsolutePosition) & "/" & Adodc1.Recordset.RecordCount
    End SubPrivate Sub Check1_KeyPress(KeyAscii As Integer)
    If KeyAscii = 13 Then
    Text1(3).SetFocus
    End IfEnd SubPrivate Sub Command1_Click(Index As Integer)
    Select Case Index
    Case 0
    If Command1(0).Caption = "添加" Then
    Command1(0).Caption = "确定"
    Command1(1).Caption = "取消"
    Adodc1.Recordset.AddNew
    aa (False)
    Else
    Command1(0).Caption = "添加"
    Command1(1).Caption = "编辑"
    Adodc1.Recordset.UpdateBatch adAffectAllChapters
    aa (True)
    End If
    Case 1
    If Command1(1).Caption = "编辑" Then
    Command1(0).Caption = "确定"
    Command1(1).Caption = "取消"
    aa (False)
    Else
    Command1(0).Caption = "添加"
    Command1(0).Caption = "确定"
    Command1(1).Caption = "取消"
    Adodc1.Recordset.CancelUpdate
    Adodc1.Refresh
    aa (True)
    End If
    Case 2
    Adodc1.Recordset.Delete
    Adodc1.Recordset.MoveNext
    End Select
    Text1(0).SetFocus
    End SubPrivate Sub aa(I As Boolean)
    Dim otxt As TextBox
    For Each otxt In Text1
    otxt.Locked = 1
    Next
    Command1(2).Visible = 1
    Adodc1.Enabled = 1End SubPrivate Sub Form_Load()End SubPrivate Sub Text1_KeyPress(Index As Integer, KeyAscii As Integer)
    If KeyAscii = 13 Then
    Select Case Index
    Case 0, 1, 3, 4, 5
    Text1(Index + 1).SetFocus
    Case 2
    Check1.SetFocus
    Case 6
    Text1(0).SetFocus
    End Select
    End If
    End SubPrivate Sub Text1_Validate(Index As Integer, Cancel As Boolean)
    Dim a(3 To 5) As Single
    Select Case Index
    Case 0 To 2
    If Text1(Index).Text = "" Then
    MsgBox "it must have data!"
    Cancel = False
    Text1(Index).SetFocus
    End If
    Case 3 To 5
    For I = 3 To 5
    a(I) = Val(Text1(I).Text)
    Next
    Text1(6).Text = a(3) + a(4) + a(5)
    End Select
    End Sub
      

  2.   

    For I = 3 To 5
    a(I) =a(I)+ Val(Text1(I).Text)
    Next